# https://hiramekun.hatenablog.com/entry/2019/06/18/184256

def main():
    MOD = 10 ** 9 + 7

    N, M = map(int, input().split())
    *s, = map(int, input().split())
    *t, = map(int, input().split())

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    acc = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(M):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = acc[i][j] + 1
            acc[i + 1][j + 1] = (acc[i + 1][j] + acc[i][j + 1] - acc[i][j] + dp[i + 1][j + 1]) % MOD
    print(acc[N][M] + 1)  # ''の分


if __name__ == '__main__':
    main()
