#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> S(n), T(m);
  for (int i = (int)(0); i < (int)(n); i++) cin >> S[i];
  map<int, vector<int>> mp;
  for (int i = (int)(0); i < (int)(m); i++) {
    cin >> T[i];
    mp[T[i]].push_back(i);
  }
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
  dp[0][0] = 1;
  for (int i = (int)(0); i < (int)(n); i++) {
    for (int j = (int)(0); j < (int)(m + 1); j++) {
      (dp[i + 1][j] += dp[i][j]) %= mod;
      auto itr = lower_bound(mp[S[i]].begin(), mp[S[i]].end(), j);
      for (auto k = itr; k != mp[S[i]].end(); k++) {
        (dp[i + 1][*k + 1] += dp[i][j]) %= mod;
      }
    }
  }
  long long ans = 0;
  for (int i = (int)(0); i < (int)(m + 1); i++) (ans += dp[n][i]) %= mod;
  cout << ans << "\n";
  return 0;
}
