#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll N, M;
ll dp[2020][2020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    vector<ll> S(N), T(M);
    REP(i, N) cin >> S[i];
    REP(j, M) cin >> T[j];

    REP(i, 2020)REP(j, 2020) dp[i][j] = 0;

    REP(i, N){
    	REP(j, M){
    		if(S[i] == T[j]){
    			dp[i+1][j+1] = 1;
    			dp[i+1][j+1] += dp[i+1][j]
    			dp[i+1][j+1] %= mod;
    			dp[i+1][j+1] += dp[i][j+1];
    			dp[i+1][j+1] %= mod;
    		}
    		else{
    			dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
    			dp[i+1][j+1] %= mod;
    			dp[i+1][j+1] -= dp[i][j]; 
    			dp[i+1][j+1] += mod;
    			dp[i+1][j+1] %= mod;
    		}
    	}
    }

    cout << (dp[N][M]+1)%mod << endl;

    return 0;
}