#include <bits/stdc++.h>
using namespace std;
const long long DIV = 1000000007;
long long mod_pow(long long M, long long N, long long mod = DIV) {
  if (N == 0) {
    return 1;
  }
  if (N == 1) {
    return M;
  }
  long long ret = mod_pow(M, N / 2, mod);
  ret = ret * ret % mod;
  if (N & 1) {
    ret = (ret * M) % mod;
  }
  return ret;
}
long long ncr(long long N, long long r, long long mod = DIV) {
  r = min(r, N - r);
  long long ret = 1;
  for (int i = 1; i <= r; i++) {
    ret = ret * (N - i + 1) % mod;
    ret = ret * mod_pow(i, mod - 2) % mod;
  }
  return ret;
}
int main() {
  long long N, M;
  vector<long long> Ss, Ts;
  cin >> N >> M;
  for (long long i = 0; i < N; i++) {
    int s;
    cin >> s;
    Ss.push_back(s);
  }
  for (long long i = 0; i < M; i++) {
    int t;
    cin >> t;
    Ts.push_back(t);
  }
  vector<vector<long long> > dp(N, vector<long long>(M, 0));
  dp[0][0] = 1;
  if (Ss[0] == Ts[0]) {
    dp[0][0] = 2;
  }
  for (long long i = 1; i < N; i++) {
    dp[i][0] = dp[i - 1][0];
    if (Ss[i] == Ts[0]) {
      dp[i][0] += 1;
    }
  }
  for (long long i = 1; i < M; i++) {
    dp[0][i] = dp[0][i - 1];
    if (Ss[0] == Ts[i]) {
      dp[0][i] += 1;
    }
  }
  for (long long n = 1; n < N; n++) {
    for (long long m = 1; m < M; m++) {
      dp[n][m] = dp[n][m - 1] + dp[n - 1][m] - dp[n - 1][m - 1];
      if (Ss[n] == Ts[m]) {
        dp[n][m] += dp[n - 1][m - 1];
        dp[n][m] = dp[n][m] % DIV;
      }
    }
  }
  cout << dp[N - 1][M - 1] << endl;
  return 0;
}
