#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N,M;
	cin>>N>>M;
	vector<int> a(N); for(auto& e:a)cin >> e;
	vector<int> b(M); for(auto& e:b)cin >> e;
	int dp[N+1][M+1] = {};
	REP(i,N+1){
		REP(j,M+1){
			if(i==0||j==0)dp[i][j] = 1;
		}
	}
	REP(i,N){
		REP(j,M){
			if(a[i]==b[j])dp[i+1][j+1] += dp[i][j+1] + dp[i+1][j];
			else dp[i+1][j+1] += dp[i+1][j] + dp[i][j+1] - dp[i][j];
			dp[i+1][j+1] %= MOD;
		}
	}
	cout<<dp[N][M]<<endl;
}
