#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;
ll dp[2020][2020];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < (N); ++i) cin >> S[i];
  for (int i = 0; i < (M); ++i) cin >> T[i];
  for (int i = 0; i < (N + 1); ++i) dp[i][0] = 1;
  for (int i = 0; i < (M + 1); ++i) dp[0][i] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      if (S[i - 1] != T[j - 1]) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
