#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
long long N, M;
long long S[2010], T[2010];
long long dp[2010][2010];
long long sum[2010][2010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (long long i = (0), i_len = (N); i < i_len; i++) {
    cin >> S[i];
  }
  for (long long i = (0), i_len = (M); i < i_len; i++) {
    cin >> T[i];
  }
  for (long long i = (0), i_len = (N); i < i_len; i++) {
    for (long long j = (0), j_len = (M); j < j_len; j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
        dp[i + 1][j + 1] %= MOD;
      }
      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 << (sum[N][M] + 1) % MOD << endl;
  return 0;
}
