N,M = (int(x) for x in input().split())
S_arr = [int(x) for x in input().split()]
T_arr = [int(x) for x in input().split()]

dp = [[1]*(M+1) for _ in range(N+1)]

mod = 1000000007
for n in range(N):
    for m in range(M):
        if S_arr[n] == T_arr[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod
        else:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod
print(dp[N][M]) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N,M = (int(x) for x in input().split()) N (int(x) for x in input().split()) M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x S_arr = [int(x) for x in input().split()] S_arr [int(x) for x in input().split()] int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x T_arr = [int(x) for x in input().split()] T_arr [int(x) for x in input().split()] [1]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [1]*(M+1) [1] 1 M+1 M 1 dp = [[1]*(M+1) for _ in range(N+1)] dp [[1]*(M+1) for _ in range(N+1)] mod = 1000000007 mod 1000000007 for n in range(N):
    for m in range(M):
        if S_arr[n] == T_arr[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod
        else:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod n range(N) range N for m in range(M):
        if S_arr[n] == T_arr[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod
        else:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod m range(M) range M if S_arr[n] == T_arr[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod
        else:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod S_arr[n] == T_arr[m] S_arr[n] S_arr n T_arr[m] T_arr m dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod dp[n+1][m+1] [n+1] dp n+1 n 1 m+1 m 1 (dp[n+1][m]+dp[n][m+1]) % mod dp[n+1][m]+dp[n][m+1] dp[n+1][m] [n+1] dp n+1 n 1 m dp[n][m+1] [n] dp n m+1 m 1 mod dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod dp[n+1][m+1] [n+1] dp n+1 n 1 m+1 m 1 (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod dp[n+1][m]+dp[n][m+1]-dp[n][m] dp[n+1][m]+dp[n][m+1] dp[n+1][m] [n+1] dp n+1 n 1 m dp[n][m+1] [n] dp n m+1 m 1 dp[n][m] [n] dp n m mod print(dp[N][M]) print dp[N][M] [N] dp N M S_arr = [int(x) for x in input().split()] [int(x) for x in input().split()] S_arr mod = 1000000007 1000000007 mod M = (int(x) for x in input().split()) (int(x) for x in input().split()) M T_arr = [int(x) for x in input().split()] [int(x) for x in input().split()] T_arr dp = [[1]*(M+1) for _ in range(N+1)] [[1]*(M+1) for _ in range(N+1)] dp N,M = (int(x) for x in input().split()) (int(x) for x in input().split()) N
N,M = (int(x) for x in input().split())
S_arr = [int(x) for x in input().split()]
T_arr = [int(x) for x in input().split()]

dp = [[1]*(M+1) for _ in range(N+1)]

mod = 1000000007
for n in range(N):
    for m in range(M):
        if S_arr[n] == T_arr[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]) % mod
        else:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]-dp[n][m]) % mod
print(dp[N][M])
