#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1LL << 60 - 1;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
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;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (long long i = 0; i < (long long)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
long long m, n, k, res, tmp, tmp2, tmp3, h, x, y;
vector<long long> a;
deque<pair<long long, long long> > que;
string s;
vector<pair<long long, long long> > g[2100600];
long long b[2100000] = {};
long long c[210000] = {};
long long rui[2100][2100];
long long dp[2200][2200];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> c[i];
  }
  dp[0][0] = 1;
  for (long long i = 0; i < n + 3; i++) {
    dp[i][0] = 1;
  }
  for (long long i = 0; i < m + 3; i++) {
    dp[0][i] = 1;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (b[i] == c[j]) {
        dp[i + 1][j + 1] += dp[i][j];
      }
      dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[n][m] << '\n';
}
