import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N, M = i2nn()
    S = i2nn()
    T = i2nn()

    rui = [[0] * (M + 1) for _ in range(N + 1)]
    #cnt = [[0] * (M) for _ in range(N)]

    n = 1
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
    print(n)

main() import sys sys from collections import deque from collections import defaultdict from heapq import heapify, heappush, heappop, heappushpop from bisect import bisect_left, bisect_right int(c) for c in s.split(' ') for c in s.split(' ') c s.split(' ') s.split s split ' ' for c in s.split(' ') int(c) int c s2nn = lambda s: [int(c) for c in s.split(' ')] s2nn lambda s: [int(c) for c in s.split(' ')] [int(c) for c in s.split(' ')] s int(s) for s in ss for s in ss s ss for s in ss int(s) int s ss2nn = lambda ss: [int(s) for s in ss] ss2nn lambda ss: [int(s) for s in ss] [int(s) for s in ss] ss s2nn(s) for s in ss for s in ss s ss for s in ss s2nn(s) s2nn s ss2nnn = lambda ss: [s2nn(s) for s in ss] ss2nnn lambda ss: [s2nn(s) for s in ss] [s2nn(s) for s in ss] ss i2s = lambda: sys.stdin.readline().rstrip() i2s lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip i2n = lambda: int(i2s()) i2n lambda: int(i2s()) int(i2s()) int i2s() i2s i2nn = lambda: s2nn(i2s()) i2nn lambda: s2nn(i2s()) s2nn(i2s()) s2nn i2s() i2s sys.stdin.readline().rstrip() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2ss lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] [sys.stdin.readline().rstrip() for _ in range(n)] n ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nn lambda n: ss2nn(ii2ss(n)) ss2nn(ii2ss(n)) ss2nn ii2ss(n) ii2ss n n ii2nnn = lambda n: ss2nnn(ii2ss(n)) ii2nnn lambda n: ss2nnn(ii2ss(n)) ss2nnn(ii2ss(n)) ss2nnn ii2ss(n) ii2ss n n MOD = int(1e+9) + 7 MOD int(1e+9) + 7 int(1e+9) int 1e+9 7 def main():
    N, M = i2nn()
    S = i2nn()
    T = i2nn()

    rui = [[0] * (M + 1) for _ in range(N + 1)]
    #cnt = [[0] * (M) for _ in range(N)]

    n = 1
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
    print(n) main N, M = i2nn() N i2nn() i2nn M S = i2nn() S i2nn() i2nn T = i2nn() T i2nn() i2nn [0] * (M + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 rui = [[0] * (M + 1) for _ in range(N + 1)] rui [[0] * (M + 1) for _ in range(N + 1)] n = 1 n 1 for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
     i s enumerate(S) enumerate S for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
     j t enumerate(T) enumerate T c = 0 c 0 if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
             s == t s t c += rui[i][j] + 1 c rui[i][j] + 1 rui[i][j] [i] rui i j 1 rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD rui[i+1][j+1] [i+1] rui i+1 i 1 j+1 j 1 (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD rui[i+1][j] + rui[i][j+1] - rui[i][j] + c rui[i+1][j] + rui[i][j+1] - rui[i][j] rui[i+1][j] + rui[i][j+1] rui[i+1][j] [i+1] rui i+1 i 1 j rui[i][j+1] [i] rui i j+1 j 1 rui[i][j] [i] rui i j c MOD n = (n + c) % MOD n (n + c) % MOD n + c n c MOD print(n) print n main() main ss2nnn = lambda ss: [s2nn(s) for s in ss] lambda ss: [s2nn(s) for s in ss] ss2nnn i2nn = lambda: s2nn(i2s()) lambda: s2nn(i2s()) i2nn ii2nnn = lambda n: ss2nnn(ii2ss(n)) lambda n: ss2nnn(ii2ss(n)) ii2nnn ii2nn = lambda n: ss2nn(ii2ss(n)) lambda n: ss2nn(ii2ss(n)) ii2nn ss2nn = lambda ss: [int(s) for s in ss] lambda ss: [int(s) for s in ss] ss2nn ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2ss def main():
    N, M = i2nn()
    S = i2nn()
    T = i2nn()

    rui = [[0] * (M + 1) for _ in range(N + 1)]
    #cnt = [[0] * (M) for _ in range(N)]

    n = 1
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
    print(n) def main():
    N, M = i2nn()
    S = i2nn()
    T = i2nn()

    rui = [[0] * (M + 1) for _ in range(N + 1)]
    #cnt = [[0] * (M) for _ in range(N)]

    n = 1
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
    print(n) main i2n = lambda: int(i2s()) lambda: int(i2s()) i2n s2nn = lambda s: [int(c) for c in s.split(' ')] lambda s: [int(c) for c in s.split(' ')] s2nn i2s = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() i2s MOD = int(1e+9) + 7 int(1e+9) + 7 MOD
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N, M = i2nn()
    S = i2nn()
    T = i2nn()

    rui = [[0] * (M + 1) for _ in range(N + 1)]
    #cnt = [[0] * (M) for _ in range(N)]

    n = 1
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            c = 0
            if s == t:
                c += rui[i][j] + 1
            #cnt[i][j] = c
            rui[i+1][j+1] = (rui[i+1][j] + rui[i][j+1] - rui[i][j] + c) % MOD
            n = (n + c) % MOD

    #for v in cnt:
    #    n = (n + sum(v)) % MOD

    #print(rui)
    #print(cnt)
    print(n)

main()
