def f():
    import sys
    input=sys.stdin.readline
    n,m=[int(i) for i in input().split()]
    s=[int(i) for i in input().split()]
    t=[int(i) for i in input().split()]
    mod=10**9+7
    dp=[[0]*(m+1) for i in range(2)]
    dp[0][0]=1
    for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
    print(dp[n%2][m])


f()

 def f():
    import sys
    input=sys.stdin.readline
    n,m=[int(i) for i in input().split()]
    s=[int(i) for i in input().split()]
    t=[int(i) for i in input().split()]
    mod=10**9+7
    dp=[[0]*(m+1) for i in range(2)]
    dp[0][0]=1
    for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
    print(dp[n%2][m]) f import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,m=[int(i) for i in input().split()] n [int(i) for i in input().split()] m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s=[int(i) for i in input().split()] s [int(i) for i in input().split()] int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i t=[int(i) for i in input().split()] t [int(i) for i in input().split()] mod=10**9+7 mod 10**9+7 10**9 10 9 7 [0]*(m+1) for i in range(2) for i in range(2) i range(2) range 2 for i in range(2) [0]*(m+1) [0] 0 m+1 m 1 dp=[[0]*(m+1) for i in range(2)] dp [[0]*(m+1) for i in range(2)] dp[0][0]=1 dp[0][0] [0] dp 0 0 1 for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
     i range(n+1) range n+1 n 1 for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
     j range(m+1) range m+1 m 1 if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
             i!=0 i 0 dp[i%2][j]=dp[(i-1)%2][j] dp[i%2][j] [i%2] dp i%2 i 2 j dp[(i-1)%2][j] [(i-1)%2] dp (i-1)%2 i-1 i 1 2 j if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
             j!=0 j 0 dp[i%2][j]+=dp[i%2][j-1] dp[i%2][j] [i%2] dp i%2 i 2 j dp[i%2][j-1] [i%2] dp i%2 i 2 j-1 j 1 if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
             i!=0 and j!=0 i!=0 i 0 j!=0 j 0 if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
             s[i-1]!=t[j-1] s[i-1] s i-1 i 1 t[j-1] t j-1 j 1 dp[i%2][j]-=dp[(i-1)%2][j-1] dp[i%2][j] [i%2] dp i%2 i 2 j dp[(i-1)%2][j-1] [(i-1)%2] dp (i-1)%2 i-1 i 1 2 j-1 j 1 dp[i%2][j]%=mod dp[i%2][j] [i%2] dp i%2 i 2 j mod print(dp[n%2][m]) print dp[n%2][m] [n%2] dp n%2 n 2 m f() f def f():
    import sys
    input=sys.stdin.readline
    n,m=[int(i) for i in input().split()]
    s=[int(i) for i in input().split()]
    t=[int(i) for i in input().split()]
    mod=10**9+7
    dp=[[0]*(m+1) for i in range(2)]
    dp[0][0]=1
    for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
    print(dp[n%2][m]) def f():
    import sys
    input=sys.stdin.readline
    n,m=[int(i) for i in input().split()]
    s=[int(i) for i in input().split()]
    t=[int(i) for i in input().split()]
    mod=10**9+7
    dp=[[0]*(m+1) for i in range(2)]
    dp[0][0]=1
    for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
    print(dp[n%2][m]) f
def f():
    import sys
    input=sys.stdin.readline
    n,m=[int(i) for i in input().split()]
    s=[int(i) for i in input().split()]
    t=[int(i) for i in input().split()]
    mod=10**9+7
    dp=[[0]*(m+1) for i in range(2)]
    dp[0][0]=1
    for i in range(n+1):
        for j in range(m+1):
            if i!=0:
                dp[i%2][j]=dp[(i-1)%2][j]
            if j!=0:
                dp[i%2][j]+=dp[i%2][j-1]
            if i!=0 and j!=0:
                if s[i-1]!=t[j-1]:
                    dp[i%2][j]-=dp[(i-1)%2][j-1]
            dp[i%2][j]%=mod
    print(dp[n%2][m])


f()


