#include <bits/stdc++.h>
using namespace std;
template <long long mod>
struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (long long)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    long long a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
};
using mint = ModInt<1000000007>;
template <class T>
struct SegmentTree {
  using F = function<T(T, T)>;
  F f;
  T inf;
  long long n;
  vector<T> node;
  SegmentTree() {}
  SegmentTree(vector<T> v, T inf, F f) : inf(inf), f(f) {
    n = 1;
    while (n < v.size()) n *= 2;
    node.resize(2 * n - 1, inf);
    for (long long i = 0; i < v.size(); i++) node[i + n - 1] = v[i];
    for (long long i = n - 2; i >= 0; i--)
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(long long k, T val) {
    k += n - 1;
    node[k] = val;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  void add(long long k, T val) {
    k += n - 1;
    node[k] += val;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  T operator[](long long x) { return getval(x, x + 1); }
  T getval(long long a, long long b) { return getval(a, b, 0, 0, n); }
  T getval(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l) return inf;
    if (a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = getval(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
  void print(long long n) {
    for (long long i = 0; i < n; i++) {
      cout << getval(i, i + 1) << " ";
    }
    cout << endl;
  }
};
signed main() {
  long long n, m;
  cin >> n >> m;
  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];
  SegmentTree<mint> seg(vector<mint>(n, 0), 0,
                        [&](mint x, mint y) { return (x + y); });
  for (long long i = 0; i < n; i++) {
    for (long long j = m - 1; j >= 0; j--) {
      if (s[i] == t[j]) {
        seg.add(j, seg.getval(0, j) + 1);
      }
    }
  }
  cout << seg.getval(0, m) + 1 << endl;
  return 0;
}
