import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p

N, M = rl()
S = rl()
T = rl()

h = defaultdict(list)
for i, t in enumerate(T):
	h[t].append(i)
bit = BIT(M+1)
for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod)
print((bit.sum(M)+1)%mod) import sys, math sys math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 1000000007 mod 1000000007 sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p BIT def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	 __init__ self.n = n self.n self n n self.nums = [0] * (n+1) self.nums self nums [0] * (n+1) [0] 0 n+1 n 1 self self n n def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	 add n, nums = self.n, self.nums n self.n self n nums self.nums self nums i += 1 i 1 while i <= n:
			nums[i] += x
			i += i & -i
	
	 i <= n i n nums[i] += x nums[i] nums i x i += i & -i i i & -i i -i i self self i i x x def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	 sum nums = self.nums nums self.nums self nums s = 0 s 0 i += 1 i 1 while i:
			s += nums[i]
			i -= i & -i
		 i s += nums[i] s nums[i] nums i i -= i & -i i i & -i i -i i return s s self self i i def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p search n, nums = self.n, self.nums n self.n self n nums self.nums self nums s, p = 0, 0 s 0 p 0 for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		 i range(n.bit_length(), -1, -1) range n.bit_length() n.bit_length n bit_length -1 -1 np = p + (1<<i) np p + (1<<i) p 1<<i 1 i if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		 np <= n and s+nums[np] < x np <= n np n s+nums[np] < x s+nums[np] s nums[np] nums np x s += nums[np] s nums[np] nums np p = np p np return p p self self x x N, M = rl() N rl() rl M S = rl() S rl() rl T = rl() T rl() rl h = defaultdict(list) h defaultdict(list) defaultdict list for i, t in enumerate(T):
	h[t].append(i) i t enumerate(T) enumerate T h[t].append(i) [t].append [t] h t append i bit = BIT(M+1) bit BIT(M+1) BIT M+1 M 1 for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod) i s enumerate(S) enumerate S vals = [] vals [] for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	 j h[s] h s vals.append((j, bit.sum(j)+1)) vals.append vals append (j, bit.sum(j)+1) j bit.sum(j)+1 bit.sum(j) bit.sum bit sum j 1 for j, v in vals:
		bit.add(j+1, v%mod) j v vals bit.add(j+1, v%mod) bit.add bit add j+1 j 1 v%mod v mod print((bit.sum(M)+1)%mod) print (bit.sum(M)+1)%mod bit.sum(M)+1 bit.sum(M) bit.sum bit sum M 1 mod N, M = rl() rl() N mod = 1000000007 1000000007 mod ri = lambda: int(input()) lambda: int(input()) ri vals = [] [] vals rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl input = sys.stdin.readline sys.stdin.readline input bit = BIT(M+1) BIT(M+1) bit T = rl() rl() T h = defaultdict(list) defaultdict(list) h rs = lambda: input().strip() lambda: input().strip() rs M = rl() rl() M S = rl() rl() S class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p BIT
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p

N, M = rl()
S = rl()
T = rl()

h = defaultdict(list)
for i, t in enumerate(T):
	h[t].append(i)
bit = BIT(M+1)
for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod)
print((bit.sum(M)+1)%mod)
