import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    mod = 1e9 + 7
    n, m = rinput()
    s = rlinput()
    t = rlinput()
    a = [1] * (m + 1)
    for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
    print(int(a[-1]))
    
    
    
main() import sys sys from math import ceil def input():
    return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip def iinput():
    return int(input()) iinput return int(input()) int(input()) int input() input def finput():
    return float(input()) finput return float(input()) float(input()) float input() input def tinput():
    return input().split() tinput return input().split() input().split() ().split () input split def rinput():
    return map(int, tinput()) rinput return map(int, tinput()) map(int, tinput()) map int tinput() tinput def rlinput():
    return list(rinput()) rlinput return list(rinput()) list(rinput()) list rinput() rinput def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)     nok m = a * b m a * b a b while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
     a != 0 and b != 0 a != 0 a 0 b != 0 b 0 if a > b:
            a %= b
        else:
            b %= a
     a > b a b a %= b a b b %= a b a return m // (a + b) m // (a + b) m a + b a b a a b b def main():
    mod = 1e9 + 7
    n, m = rinput()
    s = rlinput()
    t = rlinput()
    a = [1] * (m + 1)
    for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
    print(int(a[-1]))
    
    
     main mod = 1e9 + 7 mod 1e9 + 7 1e9 7 n, m = rinput() n rinput() rinput m s = rlinput() s rlinput() rlinput t = rlinput() t rlinput() rlinput a = [1] * (m + 1) a [1] * (m + 1) [1] 1 m + 1 m 1 for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
     j s d = a[:] d a[:] a : k = 0 k 0 for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
         i v enumerate(t) enumerate t d[i] = (k + d[i]) % mod d[i] d i (k + d[i]) % mod k + d[i] k d[i] d i mod if j == v:
                k = (k + a[i]) % mod
         j == v j v k = (k + a[i]) % mod k (k + a[i]) % mod k + a[i] k a[i] a i mod d[-1] = (k + d[-1]) % mod d[-1] d -1 (k + d[-1]) % mod k + d[-1] k d[-1] d -1 mod a = d[:] a d[:] d : print(int(a[-1])) print int(a[-1]) int a[-1] a -1 main() main def main():
    mod = 1e9 + 7
    n, m = rinput()
    s = rlinput()
    t = rlinput()
    a = [1] * (m + 1)
    for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
    print(int(a[-1]))
    
    
     def main():
    mod = 1e9 + 7
    n, m = rinput()
    s = rlinput()
    t = rlinput()
    a = [1] * (m + 1)
    for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
    print(int(a[-1]))
    
    
     main def finput():
    return float(input()) def finput():
    return float(input()) finput def tinput():
    return input().split() def tinput():
    return input().split() tinput def rlinput():
    return list(rinput()) def rlinput():
    return list(rinput()) rlinput def iinput():
    return int(input()) def iinput():
    return int(input()) iinput def input():
    return sys.stdin.readline().strip() def input():
    return sys.stdin.readline().strip() input def rinput():
    return map(int, tinput()) def rinput():
    return map(int, tinput()) rinput def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)     def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)     nok
import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    mod = 1e9 + 7
    n, m = rinput()
    s = rlinput()
    t = rlinput()
    a = [1] * (m + 1)
    for j in s:
        d = a[:]
        k = 0
        for i, v in enumerate(t):
            d[i] = (k + d[i]) % mod
            if j == v:
                k = (k + a[i]) % mod
        d[-1] = (k + d[-1]) % mod
        a = d[:]
    print(int(a[-1]))
    
    
    
main()