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