#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)

const ll INF = 1e9+7;
const int MAXN = 2*10e3;
int N,M;
int S[MAXN]={},T[MAXN]={};
static ll dp[MAXN+1][MAXN+1]={};

int main() {
  cin >> N >> M;
  REP(i,N) scanf("%d", S+i);
  REP(i,M) scanf("%d", T+i);
  REP(i,N+1) dp[i][0] = 1;
  REP(j,M+1) dp[0][j] = 1;

  RREP(i,1,N+1) {
    RREP(j,1,M+1) {
      dp[i][j] =  ((dp[i][j-1] + dp[i-1][j]) - ((S[i-1] == T[j-1])?0:dp[i-1][j-1])) % INF;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
