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 = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
 
dp_cum = [[0] * (M+1) for _ in range(N+1)]
dp_cum[0][0] = 1
for n in range(N+1):
    dp_cum[n][0] = 1
for m in range(M+1):
    dp_cum[0][m] = 1
  
for n in range(1,N+1):
    for m in range(1,M+1):
        now = 0
        if S[n] == T[m]:
            now = dp_cum[n-1][m-1]
        dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now
        dp_cum[n][m] %= MOD
print(dp_cum[N][M])  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 = [0] + list(map(int, input().split())) S [0] + list(map(int, input().split())) [0] 0 list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = [0] + list(map(int, input().split())) T [0] + list(map(int, input().split())) [0] 0 list(map(int, input().split())) list map(int, input().split()) map int 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_cum = [[0] * (M+1) for _ in range(N+1)] dp_cum [[0] * (M+1) for _ in range(N+1)] dp_cum[0][0] = 1 dp_cum[0][0] [0] dp_cum 0 0 1 for n in range(N+1):
    dp_cum[n][0] = 1 n range(N+1) range N+1 N 1 dp_cum[n][0] = 1 dp_cum[n][0] [n] dp_cum n 0 1 for m in range(M+1):
    dp_cum[0][m] = 1
   m range(M+1) range M+1 M 1 dp_cum[0][m] = 1 dp_cum[0][m] [0] dp_cum 0 m 1 for n in range(1,N+1):
    for m in range(1,M+1):
        now = 0
        if S[n] == T[m]:
            now = dp_cum[n-1][m-1]
        dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now
        dp_cum[n][m] %= MOD n range(1,N+1) range 1 N+1 N 1 for m in range(1,M+1):
        now = 0
        if S[n] == T[m]:
            now = dp_cum[n-1][m-1]
        dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now
        dp_cum[n][m] %= MOD m range(1,M+1) range 1 M+1 M 1 now = 0 now 0 if S[n] == T[m]:
            now = dp_cum[n-1][m-1]
         S[n] == T[m] S[n] S n T[m] T m now = dp_cum[n-1][m-1] now dp_cum[n-1][m-1] [n-1] dp_cum n-1 n 1 m-1 m 1 dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now dp_cum[n][m] [n] dp_cum n m dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] dp_cum[n-1][m] + dp_cum[n][m-1] dp_cum[n-1][m] [n-1] dp_cum n-1 n 1 m dp_cum[n][m-1] [n] dp_cum n m-1 m 1 dp_cum[n-1][m-1] [n-1] dp_cum n-1 n 1 m-1 m 1 now dp_cum[n][m] %= MOD dp_cum[n][m] [n] dp_cum n m MOD print(dp_cum[N][M]) print dp_cum[N][M] [N] dp_cum N M readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline T = [0] + list(map(int, input().split())) [0] + list(map(int, input().split())) T now = 0 0 now MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines dp_cum = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] dp_cum now = dp_cum[n-1][m-1] dp_cum[n-1][m-1] now S = [0] + list(map(int, input().split())) [0] + list(map(int, input().split())) S INF = 10 ** 18 10 ** 18 INF read = sys.stdin.buffer.read sys.stdin.buffer.read read N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M
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 = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
 
dp_cum = [[0] * (M+1) for _ in range(N+1)]
dp_cum[0][0] = 1
for n in range(N+1):
    dp_cum[n][0] = 1
for m in range(M+1):
    dp_cum[0][m] = 1
  
for n in range(1,N+1):
    for m in range(1,M+1):
        now = 0
        if S[n] == T[m]:
            now = dp_cum[n-1][m-1]
        dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now
        dp_cum[n][m] %= MOD
print(dp_cum[N][M]) 