#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MOD = (int)1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};
const int MAX = 1000050;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
const int MAX_N = 2050;
int n, m;
vector<int> s;
vector<int> t;
int dp[MAX_N][MAX_N];
long long sum[MAX_N][MAX_N];
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  s.resize(n);
  t.resize(m);
  for (int i = (0); i < (n); ++i) {
    cin >> s[i];
  }
  for (int i = (0); i < (m); ++i) {
    cin >> t[i];
  }
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  dp[0][0] = 1;
  for (int k = 2; k <= n + m; ++k) {
    for (int i = 1; i < k; ++i) {
      int j = k - i;
      if (j > m) {
        continue;
      }
      if (s[i - 1] != t[j - 1]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      }
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  long long ret = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      ret += (long long)dp[i][j];
      ret %= MOD;
    }
  }
  cout << ret << endl;
  return 0;
}
