#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a = LI()
    if x < a:
        print(0)
    else:
        print(10)
    return

#B
def B():
    n, x = LI()
    L = LI()
    ans = 0
    c = 1
    for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
    print(c)
    return

#C
def C():
    W, H, x, y = LI()
    a = W * H / 2
    b = 0
    if W/2 == x and H/2 == y:
        b = 1
    print(a,b)
    return

#D
def D():
    n, k = LI()
    a = LI()
    dp = [0] * (n)
    for i in range(n):
        dp[i] += dp[i - 1] + a[i]
    ans = 0
    dp.insert(0, 0)
    #print(dp)
    for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
    print(ans)

    return

#E
def E():
    n, m = LI()
    s = LI()
    t = LI()
    dp = [[0] * (m+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    for k in range(m + 1):
        dp[0][k] = 1
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
    print(dp[n][m])
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    E() from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys sys import math math import bisect bisect import random random import itertools itertools sys.setrecursionlimit(10**5) sys.setrecursionlimit sys setrecursionlimit 10**5 10 5 stdin = sys.stdin stdin sys.stdin sys stdin bisect_left = bisect.bisect_left bisect_left bisect.bisect_left bisect bisect_left bisect_right = bisect.bisect_right bisect_right bisect.bisect_right bisect bisect_right def LI(): return list(map(int, stdin.readline().split())) LI def LF(): return list(map(float, stdin.readline().split())) LF def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split())) LI_ def II(): return int(stdin.readline()) II def IF(): return float(stdin.readline()) IF def LS(): return list(map(list, stdin.readline().split())) LS def S(): return list(stdin.readline().rstrip()) S II() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) II() II def IR(n): return [II() for _ in range(n)] IR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LIR(n): return [LI() for _ in range(n)] LIR n n IF() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) IF() IF def FR(n): return [IF() for _ in range(n)] FR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LFR(n): return [LI() for _ in range(n)] LFR n n LI_() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI_() LI_ def LIR_(n): return [LI_() for _ in range(n)] LIR_ n n S() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) S() S def SR(n): return [S() for _ in range(n)] SR n n LS() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LS() LS def LSR(n): return [LS() for _ in range(n)] LSR n n mod = 1000000007 mod 1000000007 inf = float('INF') inf float('INF') float 'INF' def A():
    x, a = LI()
    if x < a:
        print(0)
    else:
        print(10)
    return

#B A x, a = LI() x LI() LI a if x < a:
        print(0)
    else:
        print(10)
     x < a x a print(0) print 0 print(10) print 10 return def B():
    n, x = LI()
    L = LI()
    ans = 0
    c = 1
    for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
    print(c)
    return

#C B n, x = LI() n LI() LI x L = LI() L LI() LI ans = 0 ans 0 c = 1 c 1 for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
     i L ans += i ans i if ans <= x:
            c += 1
            continue
         ans <= x ans x c += 1 c 1 continue break print(c) print c return def C():
    W, H, x, y = LI()
    a = W * H / 2
    b = 0
    if W/2 == x and H/2 == y:
        b = 1
    print(a,b)
    return

#D C W, H, x, y = LI() W LI() LI H x y a = W * H / 2 a W * H / 2 W * H W H 2 b = 0 b 0 if W/2 == x and H/2 == y:
        b = 1
     W/2 == x and H/2 == y W/2 == x W/2 W 2 x H/2 == y H/2 H 2 y b = 1 b 1 print(a,b) print a b return def D():
    n, k = LI()
    a = LI()
    dp = [0] * (n)
    for i in range(n):
        dp[i] += dp[i - 1] + a[i]
    ans = 0
    dp.insert(0, 0)
    #print(dp)
    for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
    print(ans)

    return

#E D n, k = LI() n LI() LI k a = LI() a LI() LI dp = [0] * (n) dp [0] * (n) [0] 0 n for i in range(n):
        dp[i] += dp[i - 1] + a[i]
     i range(n) range n dp[i] += dp[i - 1] + a[i] dp[i] dp i dp[i - 1] + a[i] dp[i - 1] dp i - 1 i 1 a[i] a i ans = 0 ans 0 dp.insert(0, 0) dp.insert dp insert 0 0 for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
     i range(1,n+1) range 1 n+1 n 1 ai = bisect_left(dp, k + dp[i-1]) ai bisect_left(dp, k + dp[i-1]) bisect_left dp k + dp[i-1] k dp[i-1] dp i-1 i 1 ans += n+1 - ai ans n+1 - ai n+1 n 1 ai print(ans) print ans return def E():
    n, m = LI()
    s = LI()
    t = LI()
    dp = [[0] * (m+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    for k in range(m + 1):
        dp[0][k] = 1
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
    print(dp[n][m])
    return

#F E n, m = LI() n LI() LI m s = LI() s LI() LI t = LI() t LI() LI [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(n+1):
        dp[i][0] = 1
     i range(n+1) range n+1 n 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for k in range(m + 1):
        dp[0][k] = 1
     k range(m + 1) range m + 1 m 1 dp[0][k] = 1 dp[0][k] [0] dp 0 k 1 for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
     i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
     j range(1, m + 1) range 1 m + 1 m 1 if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
     s[i - 1] == t[j - 1] s[i - 1] s i - 1 i 1 t[j - 1] t j - 1 j 1 dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod dp[i][j] [i] dp i j (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][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 print(dp[n][m]) print dp[n][m] [n] dp n m return def F():
    return

#G F return def G():
    return

#H G return def H():
    return

#Solve H return if __name__ == '__main__':
    E() __name__ == '__main__' __name__ '__main__' E() E def IF(): return float(stdin.readline()) def IF(): return float(stdin.readline()) IF def B():
    n, x = LI()
    L = LI()
    ans = 0
    c = 1
    for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
    print(c)
    return

#C def B():
    n, x = LI()
    L = LI()
    ans = 0
    c = 1
    for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
    print(c)
    return

#C B def LF(): return list(map(float, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) LF def H():
    return

#Solve def H():
    return

#Solve H def IR(n): return [II() for _ in range(n)] def IR(n): return [II() for _ in range(n)] IR bisect_right = bisect.bisect_right bisect.bisect_right bisect_right def C():
    W, H, x, y = LI()
    a = W * H / 2
    b = 0
    if W/2 == x and H/2 == y:
        b = 1
    print(a,b)
    return

#D def C():
    W, H, x, y = LI()
    a = W * H / 2
    b = 0
    if W/2 == x and H/2 == y:
        b = 1
    print(a,b)
    return

#D C def II(): return int(stdin.readline()) def II(): return int(stdin.readline()) II def E():
    n, m = LI()
    s = LI()
    t = LI()
    dp = [[0] * (m+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    for k in range(m + 1):
        dp[0][k] = 1
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
    print(dp[n][m])
    return

#F def E():
    n, m = LI()
    s = LI()
    t = LI()
    dp = [[0] * (m+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    for k in range(m + 1):
        dp[0][k] = 1
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
    print(dp[n][m])
    return

#F E def S(): return list(stdin.readline().rstrip()) def S(): return list(stdin.readline().rstrip()) S def LIR(n): return [LI() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] LIR def LS(): return list(map(list, stdin.readline().split())) def LS(): return list(map(list, stdin.readline().split())) LS mod = 1000000007 1000000007 mod def LFR(n): return [LI() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] LFR def F():
    return

#G def F():
    return

#G F def LIR_(n): return [LI_() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] LIR_ def G():
    return

#H def G():
    return

#H G def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split())) LI_ inf = float('INF') float('INF') inf def D():
    n, k = LI()
    a = LI()
    dp = [0] * (n)
    for i in range(n):
        dp[i] += dp[i - 1] + a[i]
    ans = 0
    dp.insert(0, 0)
    #print(dp)
    for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
    print(ans)

    return

#E def D():
    n, k = LI()
    a = LI()
    dp = [0] * (n)
    for i in range(n):
        dp[i] += dp[i - 1] + a[i]
    ans = 0
    dp.insert(0, 0)
    #print(dp)
    for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
    print(ans)

    return

#E D def LI(): return list(map(int, stdin.readline().split())) def LI(): return list(map(int, stdin.readline().split())) LI def SR(n): return [S() for _ in range(n)] def SR(n): return [S() for _ in range(n)] SR def A():
    x, a = LI()
    if x < a:
        print(0)
    else:
        print(10)
    return

#B def A():
    x, a = LI()
    if x < a:
        print(0)
    else:
        print(10)
    return

#B A stdin = sys.stdin sys.stdin stdin bisect_left = bisect.bisect_left bisect.bisect_left bisect_left def LSR(n): return [LS() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] LSR def FR(n): return [IF() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] FR
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a = LI()
    if x < a:
        print(0)
    else:
        print(10)
    return

#B
def B():
    n, x = LI()
    L = LI()
    ans = 0
    c = 1
    for i in L:
        ans += i
        if ans <= x:
            c += 1
            continue
        break
    print(c)
    return

#C
def C():
    W, H, x, y = LI()
    a = W * H / 2
    b = 0
    if W/2 == x and H/2 == y:
        b = 1
    print(a,b)
    return

#D
def D():
    n, k = LI()
    a = LI()
    dp = [0] * (n)
    for i in range(n):
        dp[i] += dp[i - 1] + a[i]
    ans = 0
    dp.insert(0, 0)
    #print(dp)
    for i in range(1,n+1):
        ai = bisect_left(dp, k + dp[i-1])
        ans += n+1 - ai
        #print(ai, i, k + dp[i-1])
    print(ans)

    return

#E
def E():
    n, m = LI()
    s = LI()
    t = LI()
    dp = [[0] * (m+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    for k in range(m + 1):
        dp[0][k] = 1
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if s[i - 1] == t[j - 1]:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%mod
            else:
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod
    print(dp[n][m])
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    E()
