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

from itertools import accumulate

def solve():
    N, M = map(int, input().split())
    S = map(int, input().split())
    *T, = map(int, input().split())
    dp = [0]*(M+1)
    for s in S:
        is_s = s.__eq__
        acc = [0]*(M+1)
        for i, t in enumerate(T):
            acc[i+1] = acc[i]+(dp[i] + 1 if is_s(t) else 0)
        *dp, = map(int.__add__, dp, acc)
    res = (dp[-1]+1)%(10**9+7)
    return str(res)

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