class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i


n, m = list(map(int, input().split()))
sss = list(map(int, input().split()))
ttt = list(map(int, input().split()))

bit = Bit(n + 1)
bit.add(1, 1)

for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1))

print(bit.sum(n + 1)) class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i Bit def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

     __init__ self.size = n self.size self size n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 n 1 self self n n def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

     sum s = 0 s 0 while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
         i > 0 i 0 s = (s + self.tree[i]) % 1000000007 s (s + self.tree[i]) % 1000000007 s + self.tree[i] s self.tree[i] self.tree self tree i 1000000007 i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i add while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i i <= self.size i self.size self size self.tree[i] = (self.tree[i] + x) % 1000000007 self.tree[i] self.tree self tree i (self.tree[i] + x) % 1000000007 self.tree[i] + x self.tree[i] self.tree self tree i x 1000000007 i += i & -i i i & -i i -i i self self i i x x n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m sss = list(map(int, input().split())) sss list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ttt = list(map(int, input().split())) ttt list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bit = Bit(n + 1) bit Bit(n + 1) Bit n + 1 n 1 bit.add(1, 1) bit.add bit add 1 1 for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1)) t ttt for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1)) i range(n - 1, -1, -1) range n - 1 n 1 -1 -1 s = sss[i] s sss[i] sss i if s != t:
            continue
         s != t s t continue bit.add(i + 2, bit.sum(i + 1)) bit.add bit add i + 2 i 2 bit.sum(i + 1) bit.sum bit sum i + 1 i 1 print(bit.sum(n + 1)) print bit.sum(n + 1) bit.sum bit sum n + 1 n 1 m = list(map(int, input().split())) list(map(int, input().split())) m s = sss[i] sss[i] s sss = list(map(int, input().split())) list(map(int, input().split())) sss n, m = list(map(int, input().split())) list(map(int, input().split())) n ttt = list(map(int, input().split())) list(map(int, input().split())) ttt class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i Bit bit = Bit(n + 1) Bit(n + 1) bit
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i


n, m = list(map(int, input().split()))
sss = list(map(int, input().split()))
ttt = list(map(int, input().split()))

bit = Bit(n + 1)
bit.add(1, 1)

for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1))

print(bit.sum(n + 1))
