#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[2123], T[2123];
map<int, vector<int>> Smp, Tmp;
long long memo[2123][2123];
long long dp(int s, int t) {
  if (s == 0 || t == 0) return 1;
  if (memo[s][t] != -1) return memo[s][t];
  long long ret = dp(s - 1, t - 1);
  if (Smp[T[t - 1]].size()) {
    for (auto ss : Smp[T[t - 1]]) {
      if (ss + 1 < s) {
        ret += dp(ss, t - 1);
        ret %= 1000000007;
      }
    }
  }
  if (Tmp[S[s - 1]].size()) {
    for (auto tt : Tmp[S[s - 1]]) {
      if (tt + 1 < t) {
        ret += dp(s - 1, tt);
        ret %= 1000000007;
      }
    }
  }
  if (S[s - 1] == T[t - 1]) {
    ret += dp(s - 1, t - 1);
    ret %= 1000000007;
  }
  return memo[s][t] = ret;
}
int main() {
  memset(memo, 0xff, sizeof(memo));
  scanf("%d%d", &N, &M);
  for (long long i = 0; i < (N); ++i) scanf("%d", &S[i]);
  for (long long i = 0; i < (M); ++i) scanf("%d", &T[i]);
  for (long long i = 0; i < (N); ++i) Smp[S[i]].push_back(i);
  for (long long i = 0; i < (M); ++i) Tmp[T[i]].push_back(i);
  printf("%lld\n", dp(N, M));
  return 0;
}
