#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return -1;
}
template <typename T>
string make_string(T N) {
  string ret;
  T now = N;
  while (now > 0) {
    T x = now % 10;
    ret += (char)('0' + x);
    now /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
template <typename T>
T lcm(T x, T y) {
  T z = __gcd(x, y);
  return x * y / z;
}
template <typename T>
bool primejudge(T n) {
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  double sqrtn = sqrt(n);
  for (T i = 3; i < sqrtn + 1; i++) {
    if (n % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
ll dp[2010][2010];
int main() {
  cout << fixed << setprecision(30);
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N), T(M);
  for (ll i = 0; i < N; i++) cin >> S[i];
  for (ll i = 0; i < M; i++) cin >> T[i];
  dp[0][0] = 1;
  for (ll i = -1; i < N; i++) {
    for (ll j = -1; j < M; j++) {
      if (i >= 0 && j >= 0 && S[i] == T[j]) dp[i + 1][j + 1] += dp[i][j];
      if (i >= 0) dp[i + 1][j + 1] += dp[i][j + 1];
      if (j >= 0) dp[i + 1][j + 1] += dp[i + 1][j];
      if (i >= 0 && j >= 0) dp[i + 1][j + 1] -= dp[i][j];
      dp[i + 1][j + 1] %= 1000000007ll;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
