#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 5, MOD = 1e9 + 7;
int dp[2005][2005];
int a[2005], b[2005], n, m;
int solve(int i1, int i2){
  if(i1 == n || i2 == m)
    return 1;
  int &ret = dp[i1][i2];
  if(~ret)
    return ret;
  ret = solve(i1+1,i2) + solve(i1, i2 + 1);
  if(ret >= MOD)ret -= MOD;
  if(a[i1] != b[i2]){
    ret -= solve(i1+1,i2+1);
    if(ret<0)ret+=MOD;
  }
  return ret;
}

int main(){

  cin >> n >> m;

  for(int i = 0; i < n; i++)
    cin >> a[i];
  for(int i = 0; i < m; i++)
    cin >> b[i];

  memset(dp,-1,sizeof dp);

  cout << solve(0,0) << '\n';


  return 0;
}
