#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << '(' << p.first << ' ' << p.second << ')';
  return os;
}
template <typename T>
void dpite(T a, T b) {
  return;
}
template <typename T>
void pite(T a, T b) {
  for (T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite;
  cout << '\n';
}
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void ios_init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
template <long long MOD>
class ModInt {
 public:
  const static long long mod = MOD;
  long long x;
  ModInt() { x = 0; }
  ModInt(long long x) {
    x %= mod;
    this->x = x < 0 ? x + mod : x;
  }
  int get() const { return (int)x; }
  ModInt& operator+=(ModInt that) {
    if ((x += that.get()) >= mod) x -= mod;
    return *this;
  }
  ModInt& operator-=(ModInt that) {
    if ((x += mod - that.get()) >= mod) x -= mod;
    return *this;
  }
  ModInt& operator*=(ModInt that) {
    x = x * that.get() % mod;
    return *this;
  }
  ModInt& operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  ModInt inverse() const {
    using std::swap;
    long long a = x, b = mod, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return ModInt(u);
  }
  ModInt pow(int n) const {
    ModInt b = *this;
    ModInt res = 1;
    while (n != 0) {
      if (n & 1) {
        res *= b;
      }
      b *= b;
      n >>= 1;
    }
    return res;
  }
  bool operator==(ModInt that) const { return x == that.get(); }
  bool operator!=(ModInt that) const { return x != that.get(); }
  ModInt operator-() const { return x == 0 ? 0 : ModInt(mod - x); }
};
template <long long MOD>
ostream& operator<<(ostream& os, const ModInt<MOD>& m) {
  os << m.get();
  return os;
}
template <long long MOD>
istream& operator>>(istream& is, ModInt<MOD>& m) {
  long long n;
  is >> n;
  m = n;
  return is;
}
class ConvQuery {
  vector<ModInt<1000000007>> fac;
  vector<ModInt<1000000007>> facinv;

 public:
  ConvQuery(int n) {
    fac = vector<ModInt<1000000007>>(n + 1);
    facinv = vector<ModInt<1000000007>>(n + 1);
    fac[0] = 1;
    facinv[0] = 1;
    for (int i = 0; i < n; ++i) {
      fac[i + 1] = fac[i] * (i + 1);
      facinv[i + 1] = fac[i + 1].inverse();
    }
  }
  ModInt<1000000007> operator()(int n, int m) {
    if (n >= 0 and 0 <= m and m <= n)
      return fac[n] * facinv[n - m] * facinv[m];
    else
      return 0;
  }
};
int main() {
  ios_init();
  int n, m;
  while (cin >> n >> m) {
    vector<int> s(n);
    for (int i = (0); i < (n); ++i) cin >> s[i];
    vector<int> t(m);
    for (int i = (0); i < (m); ++i) cin >> t[i];
    map<int, vector<int>> sid;
    for (int i = (0); i < (n); ++i) {
      sid[s[i]].push_back(i);
    }
    for (auto&& e : sid) {
      reverse((e.second).begin(), (e.second).end());
    }
    vector<int> a;
    for (int i = (0); i < (m); ++i) {
      a.insert(a.end(), (sid[t[i]]).begin(), (sid[t[i]]).end());
    }
    dpite((a).begin(), (a).end());
    vector<ModInt<1000000007>> dp(int((a).size()) + 1, ModInt<1000000007>(1));
    for (int i = (0); i < (int((a).size())); ++i) {
      true;
      for (int j = (0); j < (i); ++j) {
        if (a[j] < a[i]) {
          true;
          dp[i + 1] += dp[j + 1];
        }
      }
    }
    dpite((dp).begin(), (dp).end());
    ModInt<1000000007> ans = 0;
    for (int i = (0); i < (int((dp).size())); ++i) {
      ans += dp[i];
    }
    cout << ans << '\n';
  }
  return 0;
}
