#include <iostream>
#include <vector>


#define MOD 1000000007

using namespace std;

long long int accum[2048][2048] = {};

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> S, T;
  S.push_back(0);
  T.push_back(0);
  
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    S.push_back(tmp);
  }

  for (int i = 0; i < M; i++) {
    int tmp;
    cin >> tmp;
    T.push_back(tmp);
  }

  N++;
  M++;

  dp[0][0] = 1;
  accum[0][0] = 1;

  for (int s = 1; s < N; s++) {
    accum[s][0] = 1;
  }

  for (int t = 1; t < M; t++) {
    accum[0][t] = 1;
  }


  for (int s = 1; s < N; s++) {
    for (int t = 1; t < M; t++) {
      long long int dp;
      if (S[s] == T[t]) {
        dp = accum[s-1][t-1];
      } else {
        dp = 0;
      }

      accum[s][t] = (dp + accum[s-1][t] + accum[s][t-1] - accum[s-1][t-1]) % MOD;
    }
  }

  cout << accum[N-1][M-1] << endl;
  return 0;
}