#include <bits/stdc++.h>
using namespace std;
long long int N, M;
long long int S[2004], T[2004];
long long int dp[2004][2004];
vector<long long int> si[100004];
vector<long long int> ti[100004];
long long int ans = 0;
long long int mod = 1000000007;
signed main() {
  scanf("%lld %lld", &N, &M);
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
    si[S[i]].push_back(i);
  }
  for (long long int i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
    ti[T[i]].push_back(i);
  }
  for (long long int i = 0; i < N; i++) {
    for (long long int j = 0; j < M; j++) {
      long long int tnum =
          upper_bound(ti[S[i]].begin(), ti[S[i]].end(), j) - ti[S[i]].begin();
      if (i > 0) dp[i][j] += dp[i - 1][j];
      dp[i][j] %= mod;
      for (long long int t = 0; t < tnum; t++) {
        if (ti[S[i]][t] - 1 >= 0 && i > 0)
          dp[i][j] += dp[i - 1][ti[S[i]][t] - 1] + 1;
        else if (i == 0)
          dp[i][j] += 1;
        else if (ti[S[i]][t] - 1 < 0)
          dp[i][j] += 1;
        dp[i][j] %= mod;
      }
    }
  }
  ans = (dp[N - 1][M - 1] + 1) % mod;
  printf("%lld\n", ans % mod);
}
