import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    S = read_list()
    T = read_list()

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    for i in range(N + 1):
        dp[i][0] = 1
    
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
    print(dp[N][M])


if __name__ == "__main__":
    main()
 import bisect bisect import copy copy import heapq heapq import sys sys import itertools itertools import math math import queue queue from functools import lru_cache input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def read_values(): return map(int, input().split()) read_values def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) read_list read_list() for n in range(N) for n in range(N) n range(N) range N for n in range(N) read_list() read_list def read_lists(N): return [read_list() for n in range(N)] read_lists N N def main():
    N, M = read_values()
    S = read_list()
    T = read_list()

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    for i in range(N + 1):
        dp[i][0] = 1
    
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
    print(dp[N][M]) main N, M = read_values() N read_values() read_values M S = read_list() S read_list() read_list T = read_list() T read_list() read_list [0 for _ in range(M + 1)] for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [0 for _ in range(M + 1)] dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)] dp [[0 for _ in range(M + 1)] for _ in range(N + 1)] for i in range(N + 1):
        dp[i][0] = 1
    
     i range(N + 1) range N + 1 N 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for j in range(M + 1):
        dp[0][j] = 1

     j range(M + 1) range M + 1 M 1 dp[0][j] = 1 dp[0][j] [0] dp 0 j 1 for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
     i range(N) range N for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
     j range(M) range M dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0) dp[i][j + 1] + dp[i + 1][j] dp[i][j + 1] [i] dp i j + 1 j 1 dp[i + 1][j] [i + 1] dp i + 1 i 1 j dp[i][j] if S[i] != T[j] else 0 S[i] != T[j] S[i] S i T[j] T j dp[i][j] [i] dp i j 0 mod print(dp[N][M]) print dp[N][M] [N] dp N M if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def read_values(): return map(int, input().split()) def read_values(): return map(int, input().split()) read_values def read_lists(N): return [read_list() for n in range(N)] def read_lists(N): return [read_list() for n in range(N)] read_lists def read_list(): return list(read_values()) def read_list(): return list(read_values()) read_list input = sys.stdin.readline sys.stdin.readline input mod = 10 ** 9 + 7 10 ** 9 + 7 mod def main():
    N, M = read_values()
    S = read_list()
    T = read_list()

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    for i in range(N + 1):
        dp[i][0] = 1
    
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
    print(dp[N][M]) def main():
    N, M = read_values()
    S = read_list()
    T = read_list()

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    for i in range(N + 1):
        dp[i][0] = 1
    
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
    print(dp[N][M]) main def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    S = read_list()
    T = read_list()

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    for i in range(N + 1):
        dp[i][0] = 1
    
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - (dp[i][j] if S[i] != T[j] else 0)) % mod
    
    print(dp[N][M])


if __name__ == "__main__":
    main()

