n, m = map(int, input().split())
ss = input().split()
ts = input().split()
d = [[1] * (m+1) for _ in range(n+1)]
for i in range(n):
    for j in range(m):
        d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7)
print(d[n][m]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m ss = input().split() ss input().split() ().split () input split ts = input().split() ts input().split() ().split () input split [1] * (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) [1] * (m+1) [1] 1 m+1 m 1 d = [[1] * (m+1) for _ in range(n+1)] d [[1] * (m+1) for _ in range(n+1)] for i in range(n):
    for j in range(m):
        d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7) i range(n) range n for j in range(m):
        d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7) j range(m) range m d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7) d[i+1][j+1] [i+1] d i+1 i 1 j+1 j 1 (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7) d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j] d[i][j+1] + d[i+1][j] d[i][j+1] [i] d i j+1 j 1 d[i+1][j] [i+1] d i+1 i 1 j (ss[i] != ts[j])*d[i][j] ss[i] != ts[j] ss[i] ss i ts[j] ts j d[i][j] [i] d i j 10**9+7 10**9 10 9 7 print(d[n][m]) print d[n][m] [n] d n m d = [[1] * (m+1) for _ in range(n+1)] [[1] * (m+1) for _ in range(n+1)] d ss = input().split() input().split() ss ts = input().split() input().split() ts n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
ss = input().split()
ts = input().split()
d = [[1] * (m+1) for _ in range(n+1)]
for i in range(n):
    for j in range(m):
        d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7)
print(d[n][m])
