#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;
const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 2010;
int N, M;
vector<int> S;
vector<int> T;
int dp[MAX_N][MAX_N];
map<int, vector<int>> value_to_indices;
int memo(int l, int r) {
  if (l >= N || r >= M) {
    return 1;
  }
  int &res = dp[l][r];
  if (res >= 0) {
    return res;
  }
  res = 0;
  int a = S[l];
  auto p =
      lower_bound(value_to_indices[a].begin(), value_to_indices[a].end(), r);
  if (p != value_to_indices[a].end()) {
    int size = p - value_to_indices[a].begin();
    for (int i = size; i < value_to_indices[a].size(); i++) {
      res += memo(l + 1, value_to_indices[a][i] + 1);
      res %= MOD;
    }
  }
  res += memo(l + 1, r);
  res %= MOD;
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  S.resize(N);
  T.resize(M);
  for (auto &val : S) {
    cin >> val;
  }
  for (auto &val : T) {
    cin >> val;
  }
  for (int i = 0; i < T.size(); i++) {
    value_to_indices[T[i]].push_back(i);
  }
  memset(dp, -1, sizeof(dp));
  cout << memo(0, 0) << endl;
  return 0;
}
