# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, S, T):

    MOD = 10**9 + 7
    dp0 = [1] * (M+1)
    for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

    return dp0[-1]


def main():
    N, M = read_int_n()
    S = read_int_n()
    T = read_int_n()
    print(slv(N, M, S, T))


if __name__ == '__main__':
    main() import bisect bisect import heapq heapq import math math import random random import sys sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def read_int():
    return int(input()) read_int return int(input()) int(input()) int input() input def read_int_n():
    return list(map(int, input().split())) read_int_n return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def read_float():
    return float(input()) read_float return float(input()) float(input()) float input() input def read_float_n():
    return list(map(float, input().split())) read_float_n return list(map(float, input().split())) list(map(float, input().split())) list map(float, input().split()) map float input().split() ().split () input split def read_str():
    return input().strip() read_str return input().strip() input().strip() ().strip () input strip def read_str_n():
    return list(map(str, input().split())) read_str_n return list(map(str, input().split())) list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split def error_print(*args):
    print(*args, file=sys.stderr) error_print print(*args, file=sys.stderr) print *args args file=sys.stderr file sys.stderr sys stderr *args def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt import time time def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

     wrap s = time.time() s time.time() time.time time time ret = f(*args, **kwargs) ret f(*args, **kwargs) f *args args **kwargs kwargs e = time.time() e time.time() time.time time time error_print(e - s, 'sec') error_print e - s e s 'sec' return ret ret *args **kwargs return wrap wrap f f def slv(N, M, S, T):

    MOD = 10**9 + 7
    dp0 = [1] * (M+1)
    for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

    return dp0[-1] slv MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 dp0 = [1] * (M+1) dp0 [1] * (M+1) [1] 1 M+1 M 1 for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

     s S dp1 = dp0[:] dp1 dp0[:] dp0 : k = 0 k 0 for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
         j t enumerate(T) enumerate T if s == t:
                k += dp0[j]
             s == t s t k += dp0[j] k dp0[j] dp0 j dp1[j+1] = (dp0[j+1] + k) % MOD dp1[j+1] dp1 j+1 j 1 (dp0[j+1] + k) % MOD dp0[j+1] + k dp0[j+1] dp0 j+1 j 1 k MOD dp0 = dp1 dp0 dp1 return dp0[-1] dp0[-1] dp0 -1 N N M M S S T T @mt slv mt slv def main():
    N, M = read_int_n()
    S = read_int_n()
    T = read_int_n()
    print(slv(N, M, S, T)) main N, M = read_int_n() N read_int_n() read_int_n M S = read_int_n() S read_int_n() read_int_n T = read_int_n() T read_int_n() read_int_n print(slv(N, M, S, T)) print slv(N, M, S, T) slv N M S T if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def read_int():
    return int(input()) def read_int():
    return int(input()) read_int input = sys.stdin.readline sys.stdin.readline input def read_float_n():
    return list(map(float, input().split())) def read_float_n():
    return list(map(float, input().split())) read_float_n def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt def main():
    N, M = read_int_n()
    S = read_int_n()
    T = read_int_n()
    print(slv(N, M, S, T)) def main():
    N, M = read_int_n()
    S = read_int_n()
    T = read_int_n()
    print(slv(N, M, S, T)) main def read_str_n():
    return list(map(str, input().split())) def read_str_n():
    return list(map(str, input().split())) read_str_n def error_print(*args):
    print(*args, file=sys.stderr) def error_print(*args):
    print(*args, file=sys.stderr) error_print def read_float():
    return float(input()) def read_float():
    return float(input()) read_float def read_str():
    return input().strip() def read_str():
    return input().strip() read_str def read_int_n():
    return list(map(int, input().split())) def read_int_n():
    return list(map(int, input().split())) read_int_n def slv(N, M, S, T):

    MOD = 10**9 + 7
    dp0 = [1] * (M+1)
    for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

    return dp0[-1] def slv(N, M, S, T):

    MOD = 10**9 + 7
    dp0 = [1] * (M+1)
    for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

    return dp0[-1] slv
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, S, T):

    MOD = 10**9 + 7
    dp0 = [1] * (M+1)
    for s in S:
        dp1 = dp0[:]
        k = 0
        for j, t in enumerate(T):
            if s == t:
                k += dp0[j]
            dp1[j+1] = (dp0[j+1] + k) % MOD
        dp0 = dp1

    return dp0[-1]


def main():
    N, M = read_int_n()
    S = read_int_n()
    T = read_int_n()
    print(slv(N, M, S, T))


if __name__ == '__main__':
    main()
