import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))

dp=[[0]*(m+1) for i in range(n+1)]
sumij=[[0]*(m+1) for i in range(n+1)]
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=sumij[i][j]+1
        else:
            dp[i+1][j+1]=0
        sumij[i+1][j+1]=(sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1])%mod
print((sumij[-1][-1]+1)%mod)
# print(dp) import bisect bisect import copy copy import heapq heapq import math math import sys sys from collections import * from itertools import accumulate, combinations, permutations, product def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki return [0]+list(accumulate(lst)) [0]+list(accumulate(lst)) [0] 0 list(accumulate(lst)) list accumulate(lst) accumulate lst lst lst mod=pow(10,9)+7 mod pow(10,9)+7 pow(10,9) pow 10 9 7 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i al=[chr(ord('a') + i) for i in range(26)] al [chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] direction [[1,0],[0,1],[-1,0],[0,-1]] [1,0] 1 0 [0,1] 0 1 [-1,0] -1 0 [0,-1] 0 -1 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 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)] [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 sumij=[[0]*(m+1) for i in range(n+1)] sumij [[0]*(m+1) for i in range(n+1)] for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=sumij[i][j]+1
        else:
            dp[i+1][j+1]=0
        sumij[i+1][j+1]=(sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1])%mod i range(n) range n for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=sumij[i][j]+1
        else:
            dp[i+1][j+1]=0
        sumij[i+1][j+1]=(sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1])%mod j range(m) range m if s[i]==t[j]:
            dp[i+1][j+1]=sumij[i][j]+1
        else:
            dp[i+1][j+1]=0
         s[i]==t[j] s[i] s i t[j] t j dp[i+1][j+1]=sumij[i][j]+1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sumij[i][j]+1 sumij[i][j] [i] sumij i j 1 dp[i+1][j+1]=0 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 0 sumij[i+1][j+1]=(sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1])%mod sumij[i+1][j+1] [i+1] sumij i+1 i 1 j+1 j 1 (sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1])%mod sumij[i][j+1]+sumij[i+1][j]-sumij[i][j]+dp[i+1][j+1] sumij[i][j+1]+sumij[i+1][j]-sumij[i][j] sumij[i][j+1]+sumij[i+1][j] sumij[i][j+1] [i] sumij i j+1 j 1 sumij[i+1][j] [i+1] sumij i+1 i 1 j sumij[i][j] [i] sumij i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod print((sumij[-1][-1]+1)%mod) print (sumij[-1][-1]+1)%mod sumij[-1][-1]+1 sumij[-1][-1] [-1] sumij -1 -1 1 mod direction=[[1,0],[0,1],[-1,0],[0,-1]] [[1,0],[0,1],[-1,0],[0,-1]] direction n,m=map(int,input().split()) map(int,input().split()) n s=list(map(int,input().split())) list(map(int,input().split())) s t=list(map(int,input().split())) list(map(int,input().split())) t m=map(int,input().split()) map(int,input().split()) m dp=[[0]*(m+1) for i in range(n+1)] [[0]*(m+1) for i in range(n+1)] dp al=[chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] al def ruiseki(lst):
    return [0]+list(accumulate(lst)) def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input sumij=[[0]*(m+1) for i in range(n+1)] [[0]*(m+1) for i in range(n+1)] sumij mod=pow(10,9)+7 pow(10,9)+7 mod
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))

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