#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void coY() { cout << "Yes" << endl; }
void coN() { cout << "No" << endl; }
const ll mod = 1e9 + 7;
ll dp[2010][2010];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = (0); i < (n); ++i) cin >> s[i];
  for (int i = (0); i < (m); ++i) cin >> t[i];
  for (int si = 0; si <= n; si++) {
    for (int ti = 0; ti <= m; ti++) {
      if (ti == 0 || si == 0) {
        dp[si][ti] = 1;
        continue;
      }
      if (s[si - 1] == t[ti - 1]) {
        dp[si][ti] = (dp[si - 1][ti] + dp[si][ti - 1]) % mod;
      } else {
        dp[si][ti] =
            (dp[si - 1][ti] + dp[si][ti - 1] - dp[si - 1][ti - 1]) % mod;
      }
      dp[si][ti] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
