#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using namespace std;
long long pw(long long n, long long k) {
  if (k < 0) return pw(n, k + MOD - 1);
  long long res = 1;
  while (k) {
    if (k & 1) res *= n;
    res %= MOD;
    n *= n;
    n %= MOD;
    k >>= 1;
  }
  return res;
}
std::vector<long long> v(1e6, 0);
long long A = pw(2, 18);
long long sum(long long i) {
  long long s = 0;
  while (i) {
    s += v[i];
    s %= MOD;
    i -= i & -i;
  }
  return s;
}
void add(long long i, long long a) {
  while (i <= A) {
    v[i] += a;
    v[i] %= MOD;
    i += i & -i;
  }
}
signed main() {
  long long N, M;
  cin >> N >> M;
  std::vector<long long> s(N), t(M);
  for (long long i = 0; i < N; i++) cin >> s[i];
  for (long long i = 0; i < M; i++) cin >> t[i];
  long long ans = 1;
  std::vector<long long> po[123456];
  for (long long i = 0; i < M; i++) po[t[i]].push_back(i);
  for (long long i = N - 1; i >= 0; i--) {
    cout << 0 << endl;
    ;
    long long a = s[i];
    for (long long p : po[a]) {
      long long res = sum(A - 1) - sum(p + 1);
      res %= MOD;
      res++;
      ans += res;
      ans %= MOD;
      add(p + 1, res);
    }
  }
  cout << ans << endl;
}
