#!/usr/bin/env python
# coding: utf-8

INF = 10**9+7
def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    N, M = rli()
    ls = rli()
    lt = rli()

    dp = [[0 for _ in range(M+1)] for _ in range(N+1)]
    sdp = [[0 for _ in range(M+1)] for _ in range(N+1)]

    for n in range(N):
        s = ls[n]
        for m in range(M):
            t = lt[m]
            if s == t:
                dp[n][m] = 1
                if n > 0 and m > 0:
                    dp[n][m] += sdp[n-1][m-1]
            else:
                dp[n][m] = 0
            sdp[n][m] = dp[n][m]
            if n > 0:
                sdp[n][m] += sdp[n-1][m]
            if m > 0:
                sdp[n][m] += sdp[n][m-1]
            if n > 0 and m > 0:
                sdp[n][m] -= sdp[n-1][m-1]
            if sdp[n][m] > INF:
                sdp[n][m] %= INF
    print(sdp[N-1][M-1]+1)


if __name__ == '__main__':
    main()
