#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const long long INF = LLONG_MAX / 2;
constexpr long long MOD = 1e9 + 7;
using P = pair<long long, long long>;
using vec = vector<long long>;
using mat = vector<vec>;
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
  return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
  for (auto& vec : (matrix)) print(vec);
}
template <typename T>
void print(const vector<T> vec) {
  unsigned long long len = vec.size();
  for (long long i = (0); i <= static_cast<long long>(len - 1 - 1); i++)
    cout << vec[i] << ' ';
  cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
  cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
  cout << head << " ";
  print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
  return std::accumulate((vec).begin(), (vec).end(), T(init));
}
void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }
template <typename T>
void init(vector<T>& v) {
  for (long long i = (0); i <= static_cast<long long>(v.size() - 1); i++)
    cin >> v[i];
}
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
  assert(v.size() == w.size());
  for (long long i = (0); i <= static_cast<long long>(v.size() - 1); i++)
    cin >> v[i] >> w[i];
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vec s(n + 1), t(m + 1);
  vector<vec> memos(100000 + 1);
  for (long long i = (1); i <= static_cast<long long>(n); i++) {
    cin >> s[i];
    memos[s[i]].push_back(i);
  }
  for (long long i = (1); i <= static_cast<long long>(m); i++) {
    cin >> t[i];
  }
  vector<vec> dp(n + 1, vec(m + 1));
  for (long long i = (0); i <= static_cast<long long>(n + 1 - 1); i++)
    dp[i][0] = 1;
  for (long long i = (0); i <= static_cast<long long>(m + 1 - 1); i++)
    dp[0][i] = 1;
  for (long long i = (1); i <= static_cast<long long>(n); i++) {
    for (long long j = (1); j <= static_cast<long long>(m); j++) {
      long long sum = 0;
      for (auto& k : (memos[t[j]])) {
        if (k > i) break;
        sum += dp[k - 1][j - 1];
      }
      dp[i][j] = dp[i][j - 1] + sum;
      dp[i][j] %= MOD;
    }
  }
  print(dp[n][m]);
  return 0;
}
