# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

# Sのi文字目までと、Tのj文字目までで、dp[i][j]こ
dp = [[0]*(M+1) for _ in range(N+1)]

for r in range(1, N+1):
    for k in range(1, M+1):
        if S[r-1] == T[k-1]:
            dp[r][k] = 1+dp[r-1][k]+dp[r][k-1]
            dp[r][k] %= MOD
        else:
            dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1]
            dp[r][k] %= MOD
print((dp[-1][-1]+1) % MOD) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(input().split()) S list(input().split()) list input().split() ().split () input split T = list(input().split()) T list(input().split()) list input().split() ().split () input split [0]*(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) [0]*(M+1) [0] 0 M+1 M 1 dp = [[0]*(M+1) for _ in range(N+1)] dp [[0]*(M+1) for _ in range(N+1)] for r in range(1, N+1):
    for k in range(1, M+1):
        if S[r-1] == T[k-1]:
            dp[r][k] = 1+dp[r-1][k]+dp[r][k-1]
            dp[r][k] %= MOD
        else:
            dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1]
            dp[r][k] %= MOD r range(1, N+1) range 1 N+1 N 1 for k in range(1, M+1):
        if S[r-1] == T[k-1]:
            dp[r][k] = 1+dp[r-1][k]+dp[r][k-1]
            dp[r][k] %= MOD
        else:
            dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1]
            dp[r][k] %= MOD k range(1, M+1) range 1 M+1 M 1 if S[r-1] == T[k-1]:
            dp[r][k] = 1+dp[r-1][k]+dp[r][k-1]
            dp[r][k] %= MOD
        else:
            dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1]
            dp[r][k] %= MOD S[r-1] == T[k-1] S[r-1] S r-1 r 1 T[k-1] T k-1 k 1 dp[r][k] = 1+dp[r-1][k]+dp[r][k-1] dp[r][k] [r] dp r k 1+dp[r-1][k]+dp[r][k-1] 1+dp[r-1][k] 1 dp[r-1][k] [r-1] dp r-1 r 1 k dp[r][k-1] [r] dp r k-1 k 1 dp[r][k] %= MOD dp[r][k] [r] dp r k MOD dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1] dp[r][k] [r] dp r k dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1] dp[r-1][k]+dp[r][k-1] dp[r-1][k] [r-1] dp r-1 r 1 k dp[r][k-1] [r] dp r k-1 k 1 dp[r-1][k-1] [r-1] dp r-1 r 1 k-1 k 1 dp[r][k] %= MOD dp[r][k] [r] dp r k MOD print((dp[-1][-1]+1) % MOD) print (dp[-1][-1]+1) % MOD dp[-1][-1]+1 dp[-1][-1] [-1] dp -1 -1 1 MOD S = list(input().split()) list(input().split()) S M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N T = list(input().split()) list(input().split()) T input = sys.stdin.readline sys.stdin.readline input MOD = 10**9+7 10**9+7 MOD dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

# Sのi文字目までと、Tのj文字目までで、dp[i][j]こ
dp = [[0]*(M+1) for _ in range(N+1)]

for r in range(1, N+1):
    for k in range(1, M+1):
        if S[r-1] == T[k-1]:
            dp[r][k] = 1+dp[r-1][k]+dp[r][k-1]
            dp[r][k] %= MOD
        else:
            dp[r][k] = dp[r-1][k]+dp[r][k-1]-dp[r-1][k-1]
            dp[r][k] %= MOD
print((dp[-1][-1]+1) % MOD)
