#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  const unsigned long long MOD = 1000000007;
  int N, M;
  cin >> N >> M;
  int* S = new int[N]();
  int* T = new int[M]();
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  unsigned long long** ans = new unsigned long long*[N + 1];
  for (int i = 0; i <= N; i++) {
    ans[i] = new unsigned long long[M + 1]();
  }
  unsigned 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) % MOD << endl;
  return 0;
}
