#include <bits/stdc++.h>
using namespace std;
void input() {}
template <typename F, typename... R>
void input(F& f, R&... r) {
  cin >> f;
  input(r...);
}
template <typename F, typename... R>
void input(vector<F>& f, R&... r) {
  for (int i = 0; i < (int)(f.size()); i++) input(f[i]);
  input(r...);
}
template <typename T>
int LCS(const vector<T>& A, const vector<T>& B) {
  int n = A.size(), m = B.size();
  vector<vector<int>> lcs(n + 1, vector<int>(m + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 || j == 0) {
        lcs[i][j] = 1;
      } else if (A[i - 1] == B[j - 1]) {
        lcs[i][j] = (lcs[i][j - 1] + lcs[i - 1][j]) % 1000000007;
      } else {
        lcs[i][j] =
            (lcs[i][j - 1] + lcs[i - 1][j] + 1000000007 - lcs[i - 1][j - 1]) %
            1000000007;
      }
    }
  }
  return lcs[n][m];
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(M);
  input(S, T);
  cout << LCS(S, T) << endl;
  ;
  getchar();
  getchar();
}
