#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
template <typename T>
class SegmentTreeSum {
 private:
  int m_n;
  vector<T> m_dat;

 public:
  SegmentTreeSum(int n) {
    m_n = 1;
    while (m_n < n) m_n *= 2;
    m_dat.resize(2 * m_n - 1, 0);
  }
  void update(int k, T val) {
    k += m_n - 1;
    m_dat[k] += val;
    m_dat[k] %= MOD;
    while (k > 0) {
      k = (k - 1) / 2;
      m_dat[k] = m_dat[k * 2 + 1] + m_dat[k * 2 + 2];
      m_dat[k] %= MOD;
    }
  }
  T query(int a, int b) { return queryInternal(a, b, 0, 0, m_n); }

 private:
  T queryInternal(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b)
      return m_dat[k];
    else {
      T vl = queryInternal(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = queryInternal(a, b, k * 2 + 2, (l + r) / 2, r);
      return (vl + vr) % MOD;
    }
  }
};
int main(void) {
  cin.sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> Ss(N);
  vector<long long> Ts(M);
  for (int n = 0; n < (int)(N); ++n) cin >> Ss[n];
  for (int m = 0; m < (int)(M); ++m) cin >> Ts[m];
  SegmentTreeSum<long long> st(M);
  map<int, vector<int>> t_to_locs;
  for (int m = 0; m < (int)(M); ++m) {
    auto t = Ts[m];
    t_to_locs[t].push_back(m);
  }
  for (auto s : Ss) {
    vector<long long> added;
    for (auto loc : t_to_locs[s]) {
      added.push_back(st.query(0, loc));
    }
    int i = 0;
    for (auto loc : t_to_locs[s]) {
      st.update(loc, 1);
      st.update(loc, added[i]);
      ++i;
    }
  }
  long long ans = 1 + st.query(0, M);
  cout << ans << endl;
  return 0;
}
