'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None

if __name__ == '__main__':
    main() '''
自宅用PCでの解答
''' import math math import itertools itertools import queue queue import bisect bisect from collections import deque,defaultdict import heapq as hpq heapq from sys import stdin,setrecursionlimit ipt = stdin.readline ipt stdin.readline stdin readline setrecursionlimit(10**7) setrecursionlimit 10**7 10 7 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 dir = [(-1,0),(0,-1),(1,0),(0,1)] dir [(-1,0),(0,-1),(1,0),(0,1)] (-1,0) -1 0 (0,-1) 0 -1 (1,0) 1 0 (0,1) 0 1 alp = "abcdefghijklmnopqrstuvwxyz" alp "abcdefghijklmnopqrstuvwxyz" def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None main n,m = map(int,ipt().split()) n map(int,ipt().split()) map int ipt().split() ().split () ipt split m int(i) for i in ipt().split() for i in ipt().split() i ipt().split() ().split () ipt split for i in ipt().split() int(i) int i s = [int(i) for i in ipt().split()] s [int(i) for i in ipt().split()] int(i) for i in ipt().split() for i in ipt().split() i ipt().split() ().split () ipt split for i in ipt().split() int(i) int i t = [int(i) for i in ipt().split()] t [int(i) for i in ipt().split()] ans = 0 ans 0 [1]*(m+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [1]*(m+1) [1] 1 m+1 m 1 dp = [[1]*(m+1) for i in range(n+1)] dp [[1]*(m+1) for i in range(n+1)] for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

     i si enumerate(s) enumerate s for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

     j tj enumerate(t) enumerate t if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
             si == tj si tj dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i][j+1]+dp[i+1][j] dp[i][j+1] [i] dp i j+1 j 1 dp[i+1][j] [i+1] dp i+1 i 1 j dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i][j+1]+dp[i+1][j]-dp[i][j] dp[i][j+1]+dp[i+1][j] dp[i][j+1] [i] dp i j+1 j 1 dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j] [i] dp i j dp[i+1][j+1] %= mod dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod print(dp[n][m]) print dp[n][m] [n] dp n m return None None if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main ipt = stdin.readline stdin.readline ipt alp = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alp mod = 10**9+7 10**9+7 mod def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None main dir = [(-1,0),(0,-1),(1,0),(0,1)] [(-1,0),(0,-1),(1,0),(0,1)] dir
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None

if __name__ == '__main__':
    main()
