#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
double w, h, x, y;
long long n, m, s[2010], t[2010], dp[2010][2010], u[2010];
long long pow(long long x, long long y) {
  if (y == 0) return 1;
  if (y % 2) {
    return pow(x, y - 1) * x % mod;
  } else {
    long long yyy = pow(x, y / 2);
    return yyy * yyy % mod;
  }
}
long long div(long long x) { return pow(x, mod - 2); }
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> t[i];
  }
  dp[0][0] = 1;
  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 <= n; j++) {
      (dp[i][j] = (dp[i][j - 1] + u[j]) % mod) %= mod;
      if (s[i] == t[j]) {
        (dp[i][j] += dp[i - 1][j - 1]) %= mod;
        (u[j] += dp[i - 1][j - 1]) %= mod;
      }
    }
  }
  cout << dp[n][m] << endl;
  int www;
  cin >> www;
}
