#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
template <class T>
ostream& operator<<(ostream& s, vector<T> pair<long long, long long>) {
  for (int i = 0; i < pair<long long, long long>.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << pair<long long, long long>[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T>> pair<long long, long long>) {
  for (int i = 0; i < pair<long long, long long>.size(); ++i) {
    if (i) {
      s << endl;
    }
    s << pair<long long, long long>[i];
  }
  return s << endl;
}
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N), T(M);
  for (long long(i) = 0; (i) < (N); ++i) cin >> S[i];
  for (long long(i) = 0; (i) < (M); ++i) cin >> T[i];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1));
  vector<vector<long long>> sum(N + 1, vector<long long>(M + 1));
  dp[0][0] = 1;
  sum[0][0] = 1;
  for (long long(i) = 0; (i) < (N + 1); ++i) sum[i][0] = 1;
  for (long long(i) = 0; (i) < (M + 1); ++i) sum[0][i] = 1;
  for (long long(i) = 0; (i) < (N); ++i) {
    for (long long(j) = 0; (j) < (M); ++j) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = sum[i][j];
      else
        dp[i + 1][j + 1] = 0;
      dp[i + 1][j + 1] %= MOD;
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << sum[N][M] << endl;
  return 0;
}
