import math
from collections import deque
def main():
    t = [int(t)for t in input().split()]
    n,m = t[0],t[1]

    s = [int(z)for z in input().split()]
    t = [int(z)for z in input().split()]
    
    dp = [[0]*(m+1)for _ in range(n+1)]
    dpsum = [[0]*(m+1) for _ in range(n+1)]

    for i in range(n):
        for j in range(m):
            dpsum[i+1][j+1] = dpsum[i+1][j] + dpsum[i][j+1]
            if s[i] == t[j]:
                dpsum[i+1][j+1] += 1
    print((dpsum[n][m]+1) % (10**9+7))

if __name__ == "__main__":
    main()