#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int* S = new int[N]{-1};
  int* T = new int[M]{-1};
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  long long** ans = new long long*[N + 1];
  for (int i = 0; i <= M; i++) {
    ans[i] = new long long[M + 1]{0};
  }
  long long newVal = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      newVal = ans[i - 1][j] + ans[i][j - 1];
      if (S[i - 1] == T[j - 1]) {
        ++newVal;
      } else {
        newVal -= ans[i - 1][j - 1];
      }
      ans[i][j] = newVal;
    }
  }
  cout << (ans[N][M] + 1) % (long long)(powl(10, 9) + 7) << endl;
  return 0;
}
