#include <bits/stdc++.h>
using namespace std;
long long int N, M;
long long int S[2005], T[2005];
long long int dp[2005][2005];
vector<int> G[2005];
int main() {
  scanf("%lld %lld", &N, &M);
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  for (long long int i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  for (long long int i = 0; i < N; i++) {
    for (long long int k = 0; k < N; k++) {
      if (S[i] == T[k]) {
        G[i].push_back(k + 1);
      }
    }
  }
  for (long long int i = 0; i <= N; i++) {
    for (long long int k = 0; k <= M; k++) {
      dp[i][k] = 0;
    }
  }
  dp[0][0] = 1;
  for (long long int i = 0; i < N; i++) {
    for (long long int k = 0; k <= M; k++) {
      dp[i + 1][k] = dp[i][k];
    }
    for (long long int k = 1; k <= M; k++) {
      dp[i][k] += dp[i][k - 1];
      dp[i][k] %= 1000000007;
    }
    for (long long int k = 0; k < G[i].size(); k++) {
      dp[i + 1][G[i][k]] += dp[i][G[i][k] - 1];
      dp[i + 1][G[i][k]] %= 1000000007;
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i <= M; i++) {
    ans += dp[N][i];
    ans %= 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
