#include <bits/stdc++.h>
using namespace std;
static const long long int MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1, 0), T(M + 1, 0);
  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 int>> memo(N + 1, vector<long long int>(M + 1, 0));
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < M + 1; j++) {
      if (i == 0 || j == 0)
        memo[i][j] = 1;
      else if (S[i] != T[j])
        memo[i][j] = memo[i - 1][j] + memo[i][j - 1] - memo[i - 1][j - 1];
      else
        memo[i][j] = memo[i - 1][j] + memo[i][j - 1];
      memo[i][j] %= MOD;
    }
  }
  cout << memo[N][M] << endl;
  return 0;
}
