#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];
ll sum[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); ++i) sum[i][0] = 1;
  for (int i = 0; i < (M); ++i) sum[0][i] = 1;
  ll ans = 1;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = sum[i][j], ans = (ans + dp[i + 1][j + 1]) % MOD;
      else
        dp[i][j] = 0;
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
