#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
long exp_mod(long long a, long long b, long m) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return (long)res;
}
long fact_mod(long n, long m) {
  long long res = 1;
  for (long i = n; i > 0; --i) res = (res * i) % m;
  return (long)res;
}
long comb_mod(long n, long r) {
  long long res = 1;
  for (long i = 0; i < r; ++i) res = (res * (n - i)) % MOD;
  return (res * exp_mod(fact_mod(r, MOD), MOD - 2, MOD)) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
struct Pony {
  int x, y;
  Pony(int x_, int y_) {
    x = x_;
    y = y_;
  }
  bool operator<(const Pony &another) const { return x < another.x; };
};
long modinv(long a, long m) {
  long b = m, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
vector<long> ss[100005];
vector<long> tt[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long n, m;
  cin >> n >> m;
  vector<long> s(n);
  vector<long> t(m);
  for (int i = 0; i < (n); i++) scanf("%ld", &s[i]);
  ;
  for (int i = 0; i < (m); i++) scanf("%ld", &t[i]);
  ;
  long dp[n + 1][m + 1];
  dp[0][0] = 1;
  for (auto i = 0; i < (n); i++) {
    dp[i][0] = 1;
    ss[s[i]].push_back(i);
  }
  for (auto i = 0; i < (m); i++) {
    dp[0][i] = 1;
    tt[t[i]].push_back(i);
  }
  dp[n][0] = 1;
  dp[0][n] = 1;
  for (long i = 1; i <= n; i++) {
    long si = s[i - 1];
    for (long j = 1; j <= m; j++) {
      long tj = t[j - 1];
      dp[i][j] = dp[i][j - 1];
      for (long k : ss[tj]) {
        if (k >= i) break;
        dp[i][j] = (dp[i][j] + dp[k][j - 1]) % MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
}
