#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long int MAX = -1000000000000000000;
const long long int MIN = 1000000000000000000;
const long long int inf = 1000000000;
const long long int KOK = 100000;
const long long int LOG = 30;
const long long int li = 500005;
const long long int mod = 1000000007;
long long int n, m, b[li], a[li], k, flag, dp[2005][2005];
long long int cev;
string s;
vector<long long int> v;
inline long long int add(long long int x, long long int y) {
  if (x + y >= mod) return x + y - mod;
  return x + y;
}
inline long long int f(long long int sira, long long int son) {
  long long int cevv = 0;
  if (sira > n) return 1;
  if (son > m) return 1;
  if (~dp[sira][son]) return dp[sira][son];
  for (long long int i = son; i <= m; i++) {
    if (a[sira] == b[i]) cevv = add(cevv, f(sira + 1, i + 1));
  }
  cevv = add(cevv, f(sira + 1, son));
  return dp[sira][son] = cevv;
}
int main(void) {
  memset(dp, -1, sizeof(dp));
  scanf("%lld %lld", &n, &m);
  for (long long int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (long long int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
  }
  printf("%lld\n", f(1, 1));
  return 0;
}
