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