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