MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
            else:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j])%MOD
    print((dp[-1][-1] + 1)%MOD)

if __name__ =='__main__':
    main()    MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = 10 ** 10 INF 10 ** 10 10 10 import sys sys sys.setrecursionlimit(100000000) sys.setrecursionlimit sys setrecursionlimit 100000000 dy = (-1,0,1,0) dy (-1,0,1,0) -1 0 1 0 dx = (0,1,0,-1) dx (0,1,0,-1) 0 1 0 -1 def main():
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
            else:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j])%MOD
    print((dp[-1][-1] + 1)%MOD) main n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m s = list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split t = list(map(int,input().split())) t list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split [0] * (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) [0] * (m + 1) [0] 0 m + 1 m 1 dp = [[0] * (m + 1) for _ in range(n + 1)] dp [[0] * (m + 1) for _ in range(n + 1)] if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
     s[0] == t[0] s[0] s 0 t[0] t 0 dp[1][1] = 1 dp[1][1] [1] dp 1 1 1 dp[1][1] = 0 dp[1][1] [1] dp 1 1 0 for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][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 i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][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 i == j == 0:
                continue
             i == j == 0 i == j i j 0 continue if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][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][j + 1] + dp[i + 1][j] + 1)%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] + 1)%MOD dp[i][j + 1] + dp[i + 1][j] + 1 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 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[-1][-1] + 1)%MOD) print (dp[-1][-1] + 1)%MOD dp[-1][-1] + 1 dp[-1][-1] [-1] dp -1 -1 1 MOD if __name__ =='__main__':
    main()    __name__ =='__main__' __name__ '__main__' main() main dy = (-1,0,1,0) (-1,0,1,0) dy MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD dx = (0,1,0,-1) (0,1,0,-1) dx def main():
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
            else:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j])%MOD
    print((dp[-1][-1] + 1)%MOD) def main():
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
            else:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j])%MOD
    print((dp[-1][-1] + 1)%MOD) main INF = 10 ** 10 10 ** 10 INF
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    if s[0] == t[0]:
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(n):
        for j in range(m):
            if i == j == 0:
                continue
            if s[i] == t[j]:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
            else:
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j])%MOD
    print((dp[-1][-1] + 1)%MOD)

if __name__ =='__main__':
    main()   
