#15:35
h,w = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mod = 10 ** 9 + 7
now = [1 for _ in range(w+1)]
for i in range(h):
  last = now
  now = [1]
  for j in range(w):
    if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now)
print(now[-1]) h,w = map(int,input().split()) h map(int,input().split()) map int input().split() ().split () input split w a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b = list(map(int,input().split())) b list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 1 for _ in range(w+1) for _ in range(w+1) _ range(w+1) range w+1 w 1 for _ in range(w+1) 1 now = [1 for _ in range(w+1)] now [1 for _ in range(w+1)] for i in range(h):
  last = now
  now = [1]
  for j in range(w):
    if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now) i range(h) range h last = now last now now = [1] now [1] 1 for j in range(w):
    if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now) j range(w) range w if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now) a[i] == b[j] a[i] a i b[j] b j now.append((last[j+1]+now[-1])%mod) now.append now append (last[j+1]+now[-1])%mod last[j+1]+now[-1] last[j+1] last j+1 j 1 now[-1] now -1 mod now.append((last[j+1]+now[-1]-last[j])%mod) now.append now append (last[j+1]+now[-1]-last[j])%mod last[j+1]+now[-1]-last[j] last[j+1]+now[-1] last[j+1] last j+1 j 1 now[-1] now -1 last[j] last j mod print(now[-1]) print now[-1] now -1 h,w = map(int,input().split()) map(int,input().split()) h last = now now last a = list(map(int,input().split())) list(map(int,input().split())) a now = [1] [1] now b = list(map(int,input().split())) list(map(int,input().split())) b now = [1 for _ in range(w+1)] [1 for _ in range(w+1)] now mod = 10 ** 9 + 7 10 ** 9 + 7 mod w = map(int,input().split()) map(int,input().split()) w
#15:35
h,w = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mod = 10 ** 9 + 7
now = [1 for _ in range(w+1)]
for i in range(h):
  last = now
  now = [1]
  for j in range(w):
    if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now)
print(now[-1])