#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1000000007;
int dp[2002][2002];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1), T(M + 1);
  for (int i = 1; i <= N; i++) cin >> S[i];
  for (int i = 1; i <= M; i++) cin >> T[i];
  map<int, vector<int>> smap;
  for (int i = 1; i <= N; i++) smap[S[i]].push_back(i);
  for (int i = 1; i <= M; i++) {
    vector<int> posi = smap[T[i]];
    sort(posi.begin(), posi.end());
    int p = (posi.size() > 0) ? 0 : -1;
    for (int j = 1; j <= N; j++) {
      if (p != -1 and posi[p] == j) {
        dp[i][j] = (1 + dp[i][j - 1] - dp[i - 1][j - 1] + dp[i - 1][j] +
                    dp[i - 1][j - 1]) %
                   MOD;
        p = (p + 1 < posi.size()) ? p + 1 : -1;
      } else
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
    }
  }
  cout << 1 + dp[M][N] << endl;
  return 0;
}
