#include <bits/stdc++.h>
using namespace std;
long long dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
struct edge {
  long long to, cost;
};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool prime(long long a) {
  if (a == 1) return false;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
bool kosa(double ax, double ay, double bx, double by, double cx, double cy,
          double dx, double dy) {
  double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
  double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
  double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
  double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
  return tc * td < 0 && ta * tb < 0;
}
long long kaijo(long long n) {
  long long ans = 1;
  for (long long i = 2; i <= n; i++) {
    ans *= i;
    ans %= 1000000007;
  }
  return ans;
}
long long modpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return modpow(a, b - 1) * a % 1000000007;
  return modpow(a, b / 2) * modpow(a, b / 2) % 1000000007;
}
long long comb(long long a, long long b) {
  return kaijo(a) * modpow(kaijo(a - b), 1000000007 - 2) % 1000000007 *
         modpow(kaijo(b), 1000000007 - 2) % 1000000007;
}
long long n, m, s[2010], t[2010], dp[2010][2010];
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i + 1];
  for (long long i = 0; i < m; i++) cin >> t[i + 1];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] %= 1000000007;
    }
  }
  cout << (dp[n][m] + 1) % 1000000007 << endl;
  return 0;
}
