#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
S = LI()
T = LI()

MOD = 10 ** 9 + 7


def main():
    S.reverse()
    T.reverse()
    w = [0] * (M + 1)
    for s in S:
        l = [0] * (M + 1)
        x = 0
        for i in range(M):
            l[i + 1] = w[i + 1] + x
            if T[i] == s:
                x = (x + w[i] + 1) % MOD
                l[i + 1] = (l[i + 1] + w[i] + 1) % MOD
        w = l
    
    ans = w[-1] + 1
    print(ans)


if __name__ == "__main__":
    main()
