# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
S=[0]+LIST()
T=[0]+LIST()

dp = [[0] * (M+1) for i in range(N+1)]
for i in range(1, N+1):
    for j in range(1, M+1):
        # dp配列を2次元累積和にして、動的に更新していく
        # (+-する添字位置は、普通の区間取得の時とは違う。どうなってるかは自分のメモ参照)
        dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
        # 今回増やす数値が一致するなら
        if S[i] == T[j]:
            # そこより手前の全部合計+1
            dp[i][j]+=dp[i-1][j-1]+1
            dp[i][j]%=MOD
# 全部の合計+最初の空配列ペアの分
print((dp[N][M]+1)%MOD) import sys sys def input(): return sys.stdin.readline().strip() input [c] * b for i in range(a) for i in range(a) i range(a) range a for i in range(a) [c] * b [c] c b def list2d(a, b, c): return [[c] * b for i in range(a)] list2d a a b b c c [[d] * c for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[d] * c for j in range(b)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d a a b b c c d d def ceil(x, y=1): return int(-(-x // y)) ceil x x y=1 y 1 def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST def Yes(): print('Yes') Yes def No(): print('No') No def YES(): print('YES') YES def NO(): print('NO') NO sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N,M=MAP() N MAP() MAP M S=[0]+LIST() S [0]+LIST() [0] 0 LIST() LIST T=[0]+LIST() T [0]+LIST() [0] 0 LIST() LIST [0] * (M+1) for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [0] * (M+1) [0] 0 M+1 M 1 dp = [[0] * (M+1) for i in range(N+1)] dp [[0] * (M+1) for i in range(N+1)] for i in range(1, N+1):
    for j in range(1, M+1):
        # dp配列を2次元累積和にして、動的に更新していく
        # (+-する添字位置は、普通の区間取得の時とは違う。どうなってるかは自分のメモ参照)
        dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
        # 今回増やす数値が一致するなら
        if S[i] == T[j]:
            # そこより手前の全部合計+1
            dp[i][j]+=dp[i-1][j-1]+1
            dp[i][j]%=MOD
# 全部の合計+最初の空配列ペアの分 i range(1, N+1) range 1 N+1 N 1 for j in range(1, M+1):
        # dp配列を2次元累積和にして、動的に更新していく
        # (+-する添字位置は、普通の区間取得の時とは違う。どうなってるかは自分のメモ参照)
        dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
        # 今回増やす数値が一致するなら
        if S[i] == T[j]:
            # そこより手前の全部合計+1
            dp[i][j]+=dp[i-1][j-1]+1
            dp[i][j]%=MOD
# 全部の合計+最初の空配列ペアの分 j range(1, M+1) range 1 M+1 M 1 dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD dp[i][j] [i] dp i j (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1] dp[i-1][j]+dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 MOD if S[i] == T[j]:
            # そこより手前の全部合計+1
            dp[i][j]+=dp[i-1][j-1]+1
            dp[i][j]%=MOD
# 全部の合計+最初の空配列ペアの分 S[i] == T[j] S[i] S i T[j] T j dp[i][j]+=dp[i-1][j-1]+1 dp[i][j] [i] dp i j dp[i-1][j-1]+1 dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 1 dp[i][j]%=MOD dp[i][j] [i] dp i j MOD print((dp[N][M]+1)%MOD) print (dp[N][M]+1)%MOD dp[N][M]+1 dp[N][M] [N] dp N M 1 MOD def ceil(x, y=1): return int(-(-x // y)) def ceil(x, y=1): return int(-(-x // y)) ceil def NO(): print('NO') def NO(): print('NO') NO def YES(): print('YES') def YES(): print('YES') YES T=[0]+LIST() [0]+LIST() T def Yes(): print('Yes') def Yes(): print('Yes') Yes def INT(): return int(input()) def INT(): return int(input()) INT INF = float('inf') float('inf') INF def No(): print('No') def No(): print('No') No def list2d(a, b, c): return [[c] * b for i in range(a)] def list2d(a, b, c): return [[c] * b for i in range(a)] list2d MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST M=MAP() MAP() M def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP S=[0]+LIST() [0]+LIST() S N,M=MAP() MAP() N dp = [[0] * (M+1) for i in range(N+1)] [[0] * (M+1) for i in range(N+1)] dp def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
S=[0]+LIST()
T=[0]+LIST()

dp = [[0] * (M+1) for i in range(N+1)]
for i in range(1, N+1):
    for j in range(1, M+1):
        # dp配列を2次元累積和にして、動的に更新していく
        # (+-する添字位置は、普通の区間取得の時とは違う。どうなってるかは自分のメモ参照)
        dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
        # 今回増やす数値が一致するなら
        if S[i] == T[j]:
            # そこより手前の全部合計+1
            dp[i][j]+=dp[i-1][j-1]+1
            dp[i][j]%=MOD
# 全部の合計+最初の空配列ペアの分
print((dp[N][M]+1)%MOD)
