#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
const long long MOD = (long long)(1e9 + 7);
const int MAX_N = 2123;
int S[MAX_N];
int T[MAX_N];
long long dp[MAX_N][MAX_N];
int main2() {
  int N = nextInt();
  int M = nextInt();
  for (int i = 0, _n = (int)(N); i < _n; ++i) S[i] = nextInt();
  for (int i = 0, _n = (int)(M); i < _n; ++i) T[i] = nextInt();
  memset(dp, (0), sizeof(dp));
  for (int j = 0, _n = (int)(M + 1); j < _n; ++j) dp[0][j] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      long long res = dp[i - 1][j];
      for (int k = 0; k < j; k++) {
        if (S[i - 1] == T[k]) {
          res += dp[i - 1][k];
        }
      }
      dp[i][j] = res % MOD;
    }
  }
  long long ans = dp[N][M];
  cout << ans << endl;
  return 0;
}
int main() {
  main2();
  return 0;
}
