#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>> ans(N + 1, vector<long long>(M + 1, 1));
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < M + 1; j++) {
      ans[i][j] = (ans[i - 1][j] + ans[i][j - 1]) % mod;
      ans[i][j] %= mod;
      ans[i][j] -= ans[i - 1][j - 1];
      ans[i][j] %= mod;
      if (S[i - 1] == T[j - 1]) {
        ans[i][j] += ans[i - 1][j - 1] % mod;
        ans[i][j] %= mod;
      }
    }
  }
  long long res = ans[N][M];
  if (res < 0) res += mod;
  cout << ans[N][M] << endl;
  return 0;
}
