#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 2, inf = 1e18;
long long n, m;
std::vector<long long> A, B;
long long dp[2002][2002];
const long long mod = 1e9 + 7;
long long go(long long i, long long j) {
  if (i == n || j == m) return 1;
  long long &ret = dp[i][j];
  if (~ret) return ret;
  long long ans =
      go(i + 1, j) + go(i, j + 1) - (A[i] != B[j] ? go(i + 1, j + 1) : 0);
  ans %= mod;
  return ret = ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  A.resize(n);
  B.resize(m);
  for (long long &x : A) cin >> x;
  for (long long &x : B) cin >> x;
  memset(dp, -1, sizeof(dp));
  long long ans = go(0, 0);
  cout << ans;
}
