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