#!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
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n,x = LI()
    l = LI()
    d = 0
    ans = 1
    for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
    print(ans)
    return

#C
def C():
    w,h,x,y = LI()
    ans = w*h/2
    k = 0
    if x == w/2 and y == h/2:
        k = 1
    print(ans,k)
    return

#D
def D():
    n,k = LI()
    a = LI()
    b = [a[i] for i in range(n)]
    for i in range(n-1):
        b[i+1] += b[i]
    b.insert(0,0)
    ans = 0
    for l in range(n):
        r = bisect.bisect_left(b,b[l]+k)
        ans += n-r+1
    print(ans)
    return

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

#F
def F():
    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 def LI(): return list(map(int, sys.stdin.readline().split())) LI def I(): return int(sys.stdin.readline()) I def LS():return list(map(list, sys.stdin.readline().split())) LS def S(): return list(sys.stdin.readline())[:-1] S def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l IR None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None l = [None for i in range(n)] l [None for i in range(n)] for i in range(n):l[i] = I()
     i range(n) range n return l l n n def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l LIR None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None l = [None for i in range(n)] l [None for i in range(n)] for i in range(n):l[i] = LI()
     i range(n) range n return l l n n def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l SR None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None l = [None for i in range(n)] l [None for i in range(n)] for i in range(n):l[i] = S()
     i range(n) range n return l l n n def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l LSR None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None l = [None for i in range(n)] l [None for i in range(n)] for i in range(n):l[i] = LS()
     i range(n) range n return l l n n sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 1000000007 mod 1000000007 def A():
    x,n = LI()
    if x < n:
        print(0)
    else:
        print(10)
    return

#B A x,n = LI() x LI() LI n if x < n:
        print(0)
    else:
        print(10)
     x < n x n print(0) print 0 print(10) print 10 return def B():
    n,x = LI()
    l = LI()
    d = 0
    ans = 1
    for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
    print(ans)
    return

#C B n,x = LI() n LI() LI x l = LI() l LI() LI d = 0 d 0 ans = 1 ans 1 for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
     i range(n) range n d += l[i] d l[i] l i if d <= x:
            ans += 1
     d <= x d x ans += 1 ans 1 print(ans) print ans return def C():
    w,h,x,y = LI()
    ans = w*h/2
    k = 0
    if x == w/2 and y == h/2:
        k = 1
    print(ans,k)
    return

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

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

#Solve F return if __name__ == "__main__":
    E() __name__ == "__main__" __name__ "__main__" E() E def LS():return list(map(list, sys.stdin.readline().split())) def LS():return list(map(list, sys.stdin.readline().split())) LS def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l LSR def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def D():
    n,k = LI()
    a = LI()
    b = [a[i] for i in range(n)]
    for i in range(n-1):
        b[i+1] += b[i]
    b.insert(0,0)
    ans = 0
    for l in range(n):
        r = bisect.bisect_left(b,b[l]+k)
        ans += n-r+1
    print(ans)
    return

#E def D():
    n,k = LI()
    a = LI()
    b = [a[i] for i in range(n)]
    for i in range(n-1):
        b[i+1] += b[i]
    b.insert(0,0)
    ans = 0
    for l in range(n):
        r = bisect.bisect_left(b,b[l]+k)
        ans += n-r+1
    print(ans)
    return

#E D def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l SR def C():
    w,h,x,y = LI()
    ans = w*h/2
    k = 0
    if x == w/2 and y == h/2:
        k = 1
    print(ans,k)
    return

#D def C():
    w,h,x,y = LI()
    ans = w*h/2
    k = 0
    if x == w/2 and y == h/2:
        k = 1
    print(ans,k)
    return

#D C mod = 1000000007 1000000007 mod def A():
    x,n = LI()
    if x < n:
        print(0)
    else:
        print(10)
    return

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

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

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

#F E def S(): return list(sys.stdin.readline())[:-1] def S(): return list(sys.stdin.readline())[:-1] S def B():
    n,x = LI()
    l = LI()
    d = 0
    ans = 1
    for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
    print(ans)
    return

#C def B():
    n,x = LI()
    l = LI()
    d = 0
    ans = 1
    for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
    print(ans)
    return

#C B def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l LIR def F():
    return

#Solve def F():
    return

#Solve F def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l IR
#!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
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n,x = LI()
    l = LI()
    d = 0
    ans = 1
    for i in range(n):
        d += l[i]
        if d <= x:
            ans += 1
    print(ans)
    return

#C
def C():
    w,h,x,y = LI()
    ans = w*h/2
    k = 0
    if x == w/2 and y == h/2:
        k = 1
    print(ans,k)
    return

#D
def D():
    n,k = LI()
    a = LI()
    b = [a[i] for i in range(n)]
    for i in range(n-1):
        b[i+1] += b[i]
    b.insert(0,0)
    ans = 0
    for l in range(n):
        r = bisect.bisect_left(b,b[l]+k)
        ans += n-r+1
    print(ans)
    return

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

#F
def F():
    return

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