// C++ program to count common subsequence in two strings
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;

int a1,a2,dp[2003][2003],s[2004],t[2004];

// return the number of common subsequence in
// two strings
int CommomSubsequencesCount(){

    // for each character of S
    for (int i = 1; i <= a1; i++) {

        // for each charcater in T
        for (int j = 1; j <= a2; j++) {

            // if character are same in both
            // the string
            if (s[i] == t[j]){
                dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
                dp[i][j]=dp[i][j]%mod;
            }
            else{
                dp[i][j] = dp[i][j - 1] + dp[i - 1][j] -
                                        dp[i - 1][j - 1];
                dp[i][j]=dp[i][j]%mod;
            }
        }
    }
    return dp[a1][a2];
}

// Driver Program
int main()
{
    cin >> a1 >> a2;
    for(int i=1;i<=a1;i++) cin >> s[i];
    for(int i=1;i<=a2;i++) cin >> t[i];

    cout << CommomSubsequencesCount() + 1 << endl;

}
