#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;
const ll INF = 1e18, MOD = 1e9 + 7;
const int MAX = 1e3;
ll dp[MAX][MAX];
vii a, b;
ll f(const int i, const int j) {
  if (i == -1 or j == -1) return 0;
  ll &res = dp[i][j];
  if (res != -1) return res;
  res = (f(i - 1, j) + f(i, j - 1)) % MOD;
  if (a[i] == b[j])
    res++;
  else
    res += MOD - f(i - 1, j - 1);
  res %= MOD;
  return res;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  memset(dp, -1, sizeof dp);
  int n, m;
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  for (auto &e : a) {
    cin >> e;
  }
  for (auto &e : b) {
    cin >> e;
  }
  cout << (f(n - 1, m - 1) + 1) % MOD << '\n';
}
