#include <bits/stdc++.h>
using namespace std;
inline long long qpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAXN = 2e3 + 7;
long long dp[MAXN][MAXN];
int a[MAXN], b[MAXN];
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) dp[i][0] = 1;
  for (int i = 1; i <= m; ++i) dp[0][i] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      if (a[i] != b[j]) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
