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

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

    return str(res)

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