# -*- coding: utf-8 -*-

def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD)

if __name__ == '__main__':
    main() def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD) main import sys sys def input(): return sys.stdin.readline().strip()
     input [c] * b for i in range(a) for i in range(a) i range(a) range a for i in range(a) [c] * b [c] c b def list2d(a, b, c): return [[c] * b for i in range(a)]
     list2d a a b b c c [[d] * c for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[d] * c for j in range(b)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
     list3d a a b b c c d d def ceil(x, y=1): return int(-(-x // y))
     ceil x x y=1 y 1 def INT(): return int(input())
     INT def MAP(): return map(int, input().split())
     MAP def LIST(): return list(map(int, input().split()))
     LIST def Yes(): print('Yes')
     Yes def No(): print('No')
     No def YES(): print('YES')
     YES def NO(): print('NO')
     NO sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N,M=MAP() N MAP() MAP M S=LIST() S LIST() LIST T=LIST() T LIST() LIST dp1=list2d(N+2, M+2, 0) dp1 list2d(N+2, M+2, 0) list2d N+2 N 2 M+2 M 2 0 dp2=list2d(N+2, M+2, 0) dp2 list2d(N+2, M+2, 0) list2d N+2 N 2 M+2 M 2 0 dp1[0][0]=1 dp1[0][0] [0] dp1 0 0 1 for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
     i range(N+1) range N+1 N 1 for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
     j range(M+1) range M+1 M 1 dp1[i][j]%=MOD dp1[i][j] [i] dp1 i j MOD dp1[i+1][j]+=dp1[i][j] dp1[i+1][j] [i+1] dp1 i+1 i 1 j dp1[i][j] [i] dp1 i j dp2[i][j]+=dp1[i][j] dp2[i][j] [i] dp2 i j dp1[i][j] [i] dp1 i j dp2[i][j+1]+=dp2[i][j] dp2[i][j+1] [i] dp2 i j+1 j 1 dp2[i][j] [i] dp2 i j if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
     i<N and j<M and S[i]==T[j] i<N and j<M i<N i N j<M j M S[i]==T[j] S[i] S i T[j] T j dp1[i+1][j+1]+=dp2[i][j] dp1[i+1][j+1] [i+1] dp1 i+1 i 1 j+1 j 1 dp2[i][j] [i] dp2 i j print((dp2[N][M])%MOD) print (dp2[N][M])%MOD dp2[N][M] [N] dp2 N M MOD if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD) def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD) main
# -*- coding: utf-8 -*-

def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD)

if __name__ == '__main__':
    main()
