#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto &v : S) cin >> v;
  for (auto &v : T) cin >> v;
  vector<long long int> last(N + 1, 1);
  for (int j = 1; j <= M; ++j) {
    vector<long long int> crr(N + 1, 1);
    for (int i = 1; i <= N; ++i) {
      crr[i] = last[i];
      if (S[i - 1] == T[i - 1]) crr[i] += last[i - 1] % 1000000007;
    }
    last = move(crr);
  }
  cout << last.back() << endl;
}
