# -*- coding: utf-8 -*-
"""
Created on Sun Jun 16 20:56:46 2019

@author: Yamazaki Kenichi
"""

N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9 + 7

A = [[1 for j in range(M+1)]]
A += [[0 for j in range(M+1)] for i in range(N)]
A += [[1 for j in range(M+1)]]
for i in range(N):
#    print(i,j)
    for j in range(M):
#        print(i,j)
        if T[j] == S[i]:
            A[i+1][j] = A[-1][j-1] % mod
        else:
            A[i+1][j] = A[i+1][j-1] % mod
        A[-1][j] += A[i+1][j]
        A[-1][j] %= mod
#        print(A)
ans = A[-1][-2]
print(ans)