#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
long long const INF = 1e18;
template <typename T>
int size(const T& a) {
  return (int)a.size();
}
template <typename T>
T Div(T a, T b) {
  return (a + b - 1) / b;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (auto& i : s) cin >> i;
  for (auto& i : t) cin >> i;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));
  vector<vector<long long>> v(1e5 + 10);
  for (int(i) = (1); (i) < (n + 1); i++) {
    long long x = s[i - 1];
    v[x].push_back(i);
    for (int(j) = 0; (j) < (m); (j)++) {
      long long y = t[j];
      dp[i][j + 1] = dp[i][j];
      for (auto e : v[y]) {
        dp[i][j + 1] += dp[e - 1][j];
        dp[i][j + 1] %= MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
