#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
template <class T>
pair<T, size_t> max(vector<T> &x) {
  auto it = max_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
pair<T, size_t> min(vector<T> &x) {
  auto it = min_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline ll IN() {
  ll x;
  cin >> x;
  return x;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vi S(N);
  vi T(M);
  for (int i = int(0); i < int(N); ++i) cin >> S[i];
  for (int i = int(0); i < int(M); ++i) cin >> T[i];
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
  vector<vector<ll>> sum(N + 1, vector<ll>(M + 1, 0));
  ll mod = 1000000007;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i == 0 || j == 0) {
        sum[i][j] = 1;
      } else {
        sum[i][j] = (sum[i][j - 1] + sum[i - 1][j]) % mod;
        if (S[i - 1] != T[j - 1]) sum[i][j] -= sum[i - 1][j - 1];
        sum[i][j] %= mod;
      }
    }
  };
  ;
  cout << sum[N][M] << endl;
  return 0;
}
