#include <bits/stdc++.h>
using namespace std;
const long long int E = 1e18 + 7;
const long long int MOD = 1000000007;
template <class... A>
void prints() {
  cout << endl;
}
template <class... A>
void prints_rest() {
  cout << endl;
}
template <class T, class... A>
void prints_rest(const T &first, const A &...rest) {
  cout << " " << first;
  prints_rest(rest...);
}
template <class T, class... A>
void prints(const T &first, const A &...rest) {
  cout << first;
  prints_rest(rest...);
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int second[N], T[M];
  int A[N + 1][M + 1], B[N + 1][M + 1];
  for (int i = 0; i < N; i++) {
    cin >> second[i];
    A[i][0] = 0;
    B[i][0] = 1;
  }
  for (int j = 0; j < M; j++) {
    cin >> T[j];
    A[0][j] = 0;
    B[0][j] = 1;
  }
  A[0][0] = 1;
  A[N][0] = 0;
  B[N][0] = 1;
  A[0][M] = 0;
  B[0][M] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < M + 1; j++) {
      if (second[i - 1] == T[j - 1]) {
        A[i][j] = B[i - 1][j - 1];
      } else {
        A[i][j] = 0;
      }
      B[i][j] = (((B[i - 1][j] + B[i][j - 1]) % MOD - B[i - 1][j - 1]) % MOD +
                 A[i][j]) %
                MOD;
    }
  }
  prints(B[N][M]);
}
