from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
s = LI()
t = LI()
dp = [[1] * (m + 1) for _ in range(n + 1)]


for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod



print(dp[n][m]) from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math math import bisect bisect import random random from itertools import permutations, accumulate, combinations, product import sys sys import string string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce INF = float('inf') INF float('inf') float 'inf' def LI(): return list(map(int, sys.stdin.readline().split())) LI def I(): return int(sys.stdin.readline()) I def LS(): return sys.stdin.readline().split() LS def S(): return sys.stdin.readline().strip() S I() for i in range(n) for i in range(n) i range(n) range n for i in range(n) I() I def IR(n): return [I() for i in range(n)] IR n n LI() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LI() LI def LIR(n): return [LI() for i in range(n)] LIR n n S() for i in range(n) for i in range(n) i range(n) range n for i in range(n) S() S def SR(n): return [S() for i in range(n)] SR n n LS() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LS() LS def LSR(n): return [LS() for i in range(n)] LSR n n list(S()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(S()) list S() S def SRL(n): return [list(S()) for i in range(n)] SRL n n [int(j) for j in list(S())] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [int(j) for j in list(S())] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] MSRL n n mod = 1000000007 mod 1000000007 n, m = LI() n LI() LI m s = LI() s LI() LI t = LI() t LI() LI [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)] for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod i range(n) range n for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod j range(m) range m if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod s[i] == t[j] s[i] s i t[j] t j dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 (dp[i + 1][j] + dp[i][j + 1]) % mod 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 mod dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod dp[i][j + 1] + dp[i + 1][j] - dp[i][j] dp[i][j + 1] + dp[i + 1][j] dp[i][j + 1] [i] dp i j + 1 j 1 dp[i + 1][j] [i + 1] dp i + 1 i 1 j dp[i][j] [i] dp i j mod print(dp[n][m]) print dp[n][m] [n] dp n m def SR(n): return [S() for i in range(n)] def SR(n): return [S() for i in range(n)] SR dp = [[1] * (m + 1) for _ in range(n + 1)] [[1] * (m + 1) for _ in range(n + 1)] dp t = LI() LI() t def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] MSRL def LIR(n): return [LI() for i in range(n)] def LIR(n): return [LI() for i in range(n)] LIR m = LI() LI() m def LSR(n): return [LS() for i in range(n)] def LSR(n): return [LS() for i in range(n)] LSR def IR(n): return [I() for i in range(n)] def IR(n): return [I() for i in range(n)] IR def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I mod = 1000000007 1000000007 mod def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI n, m = LI() LI() n def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def S(): return sys.stdin.readline().strip() def S(): return sys.stdin.readline().strip() S def SRL(n): return [list(S()) for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] SRL s = LI() LI() s INF = float('inf') float('inf') INF
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
s = LI()
t = LI()
dp = [[1] * (m + 1) for _ in range(n + 1)]


for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod



print(dp[n][m])