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