#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S, T;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    S.push_back(x);
  }
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    T.push_back(x);
  }
  vector<int> X;
  X.push_back(1);
  for (int i = 0; i < N; i++) {
    X.push_back(1);
  }
  for (int y = 0; y < M; y++) {
    vector<int> last = X;
    for (int x = 0; x < N; x++) {
      if (T[y] == S[x]) {
        X[x + 1] = (X[x] + X[x + 1]) % 1000000007;
      } else {
        X[x + 1] = (X[x] + X[x + 1] - last[x] + 1000000007) % 1000000007;
      }
    }
  }
  cout << X[N];
  return 0;
}
