import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

S.append(0)
T.append(0)
MAX = 2005
dp0 = [[0] * MAX for _ in range(MAX)]
dp1 = [[0] * MAX for _ in range(MAX)]

dp0[0][0] = 1
for i in range(N + 1):
    for j in range(M + 1):
        dp0[i + 1][j] += dp0[i][j] % MOD
        dp1[i][j] += dp0[i][j] % MOD
        dp1[i][j + 1] += dp1[i][j] % MOD
        if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD
print(dp1[N][M] % MOD) import sys sys import itertools itertools import time time import math math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split S.append(0) S.append S append 0 T.append(0) T.append T append 0 MAX = 2005 MAX 2005 [0] * MAX for _ in range(MAX) for _ in range(MAX) _ range(MAX) range MAX for _ in range(MAX) [0] * MAX [0] 0 MAX dp0 = [[0] * MAX for _ in range(MAX)] dp0 [[0] * MAX for _ in range(MAX)] [0] * MAX for _ in range(MAX) for _ in range(MAX) _ range(MAX) range MAX for _ in range(MAX) [0] * MAX [0] 0 MAX dp1 = [[0] * MAX for _ in range(MAX)] dp1 [[0] * MAX for _ in range(MAX)] dp0[0][0] = 1 dp0[0][0] [0] dp0 0 0 1 for i in range(N + 1):
    for j in range(M + 1):
        dp0[i + 1][j] += dp0[i][j] % MOD
        dp1[i][j] += dp0[i][j] % MOD
        dp1[i][j + 1] += dp1[i][j] % MOD
        if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD i range(N + 1) range N + 1 N 1 for j in range(M + 1):
        dp0[i + 1][j] += dp0[i][j] % MOD
        dp1[i][j] += dp0[i][j] % MOD
        dp1[i][j + 1] += dp1[i][j] % MOD
        if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD j range(M + 1) range M + 1 M 1 dp0[i + 1][j] += dp0[i][j] % MOD dp0[i + 1][j] [i + 1] dp0 i + 1 i 1 j dp0[i][j] % MOD dp0[i][j] [i] dp0 i j MOD dp1[i][j] += dp0[i][j] % MOD dp1[i][j] [i] dp1 i j dp0[i][j] % MOD dp0[i][j] [i] dp0 i j MOD dp1[i][j + 1] += dp1[i][j] % MOD dp1[i][j + 1] [i] dp1 i j + 1 j 1 dp1[i][j] % MOD dp1[i][j] [i] dp1 i j MOD if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD S[i] == T[j] S[i] S i T[j] T j dp0[i + 1][j + 1] += dp1[i][j] % MOD dp0[i + 1][j + 1] [i + 1] dp0 i + 1 i 1 j + 1 j 1 dp1[i][j] % MOD dp1[i][j] [i] dp1 i j MOD print(dp1[N][M] % MOD) print dp1[N][M] % MOD dp1[N][M] [N] dp1 N M MOD INF = 10 ** 18 10 ** 18 INF read = sys.stdin.buffer.read sys.stdin.buffer.read read M = map(int, input().split()) map(int, input().split()) M readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines S = list(map(int, input().split())) list(map(int, input().split())) S N, M = map(int, input().split()) map(int, input().split()) N dp1 = [[0] * MAX for _ in range(MAX)] [[0] * MAX for _ in range(MAX)] dp1 MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline T = list(map(int, input().split())) list(map(int, input().split())) T MAX = 2005 2005 MAX dp0 = [[0] * MAX for _ in range(MAX)] [[0] * MAX for _ in range(MAX)] dp0
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

S.append(0)
T.append(0)
MAX = 2005
dp0 = [[0] * MAX for _ in range(MAX)]
dp1 = [[0] * MAX for _ in range(MAX)]

dp0[0][0] = 1
for i in range(N + 1):
    for j in range(M + 1):
        dp0[i + 1][j] += dp0[i][j] % MOD
        dp1[i][j] += dp0[i][j] % MOD
        dp1[i][j + 1] += dp1[i][j] % MOD
        if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD
print(dp1[N][M] % MOD)
