#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e3 + 123;

int a[N], b[N]; 
int dp[N][N];
int sum[N][N];
int n, m;

int add(int a, int b)
{
	a += b;
	if(a >= mod) a %= mod;
	return a;
}

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int j = 1; j <= m; j++) cin >> b[j];
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			if(a[i] != b[j]) dp[i][j] = 0;
			else dp[i][j] = add(sum[i - 1][j - 1], 1);
			sum[i][j] = add(sum[i - 1][j], sum[i][j - 1]);
			sum[i][j] = add(sum[i][j], -sum[i - 1][j - 1]);
			sum[i][j] = add(sum[i][j], dp[i][j]);
		}
	sum[n][m] = add(sum[n][m], 1);
	cout << sum[n][m];
}                                