#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
const long long N = 3e3;
long long n, x[N], m, y[N], dp[N][N];
void solve() {
  for (long long i = 0; i <= n; ++i) {
    for (long long j = 0; j <= m; ++j) {
      dp[i][j] =
          ((i < 1) | (j < 1) ? 1
                             : dp[i - 1][j] + dp[i][j - 1] -
                                   (x[i] == y[j] ? 0 : dp[i - 1][j - 1])) %
          mod;
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m];
  exit(0);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    cin >> x[i];
  }
  for (long long i = 1; i <= m; ++i) {
    cin >> y[i];
  }
  solve();
  return 0;
}
