#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> T.at(i);
  }
  vector<vector<int>> index(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i) == T.at(j)) {
        index.at(i).push_back(j);
      }
    }
  }
  long long ans = 1;
  vector<map<int, long long>> sum(N);
  for (int i = 0; i < N; i++) {
    if (index.at(i).size() == 0) {
      continue;
    }
    for (int k = 0; k < index.at(i).size(); k++) {
      sum.at(i)[index.at(i).at(k)] = 1;
      for (int j = 0; j < i; j++) {
        for (auto m : sum.at(j)) {
          if (m.first < index.at(i).at(k)) {
            sum.at(i)[index.at(i).at(k)] += m.second;
            sum.at(i)[index.at(i).at(k)] %= 1000000007;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (auto m : sum.at(i)) {
      ans += m.second;
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
}
