import collections
import math
N, M = map(int, input().split())

S = list(map(int, input().split()))
T = list(map(int, input().split()))

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


for i in range(1, N + 1):
  _i = i - 1
  for j in range(1, M + 1):
    _j = j - 1
    if S[_i] == T[_j]:
      memo[i][j] = _sum[_i][_j] + 1
    _sum[i][j] = _sum[_i][j] + _sum[i][_j] - _sum[_i][_j] + memo[i][j]


print(_sum[-1][-1] % int(10**9 + 7) + 1)

