# -*- coding: utf-8 -*-

def solve():
    N, M = map(int, input().split())
    *S, = map(int, input().split())
    *T, = map(int, input().split())
    dp = [[[0]*3 for _ in range(M+1)] for _ in range(2)]
    k,l = 0,1
    for j, s in enumerate(S, start=1):
        k,l = l,k
        for i, t in enumerate(T, start=1):
            dp[k][i] = [sum(dp[l][i]), sum(dp[k][i-1][1:]), sum(dp[l][i-1]) + 1 if t == s else 0]
    res = (sum(dp[N%2][-1]) + 1)%(10**9+7)

    return str(res)

if __name__ == '__main__':
    print(solve())
