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

def solve():
    N, M = map(int, input().split())
    *S, = map(int, input().split())
    *T, = map(int, input().split())
    dph = [[0]*(M+1), [0]*(M+1)]
    dpv = [[0]*(M+1), [0]*(M+1)]
    dpr = [[0]*(M+1), [0]*(M+1)]
    for j, s in enumerate(S, start=1):
        for i, t in enumerate(T, start=1):
            dph[j%2][i] = dph[(j-1)%2][i] + dpv[(j-1)%2][i] + dpr[(j-1)%2][i]
            dpv[j%2][i] = dpv[j%2][i-1] + dpr[j%2][i-1]
            dpr[j%2][i] = dph[(j-1)%2][i-1] + dpv[(j-1)%2][i-1] + dpr[(j-1)%2][i-1] + 1 if t == s else 0
    res = (dph[N%2][-1] + dpv[N%2][-1] + dpr[N%2][-1] + 1)%(10**9+7)


    return str(res)

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