#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100101;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first + b.first, a.second + b.second);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first - b.first, a.second - b.second);
}
template <typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.first + a.second * b.second);
}
template <typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.second - a.second * b.first);
}
template <typename T>
void print(vector<T> vec, string name = "") {
  cout << name;
  for (auto u : vec) cout << u << ' ';
  cout << '\n';
}
struct FENWICK {
  vector<long long> A;
  int N;
  FENWICK(int n) : N(n) { A.resize(n + 1, 0); }
  void add(int i, long long first) {
    for (; i <= N; i += (i) & (-i)) A[i] = (first + A[i]) % MOD;
  }
  long long getQ(int i) {
    long long get = 1;
    for (; i > 0; i -= (i) & (-i)) get = (A[i] + get) % MOD;
    return get;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> pir(N);
  vector<int> ant(M);
  for (int i = 0; i < N; ++i) cin >> pir[i];
  for (int i = 0; i < M; ++i) cin >> ant[i];
  FENWICK sums(N);
  for (int i = 0; i < N; ++i)
    for (int j = M - 1; j >= 0; --j)
      if (pir[i] == ant[j]) sums.add(j + 1, sums.getQ(j));
  printf("%lld\n", sums.getQ(N));
}
