#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const long long MOD = 1000000007;
ll N, M;
vector<ll> S, T;
const ll MAX_N = 2 * (1e3);
ll dp[MAX_N + 5][MAX_N + 5];
map<ll, vector<ll>> mp;
ll dfs(int i, int j) {
  if (i < 0 || j < 0) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  dp[i][j] = dfs(i - 1, j);
  for (ll v : mp[S[i]]) {
    if (v > j) {
      break;
    }
    dp[i][j]++;
    dp[i][j] += dfs(i - 1, v - 1);
    dp[i][j] %= MOD;
  }
  return dp[i][j];
}
void solve(long long N, long long M) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < M; i++) {
    mp[T[i]].push_back(i);
  }
  cout << (dfs(N - 1, M - 1) + 1) % MOD << endl;
}
int main() {
  scanf("%lld", &N);
  scanf("%lld", &M);
  S.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  T.resize(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  solve(N, M);
  return 0;
}
