#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const int maxn = 2005;
ll dp[maxn][maxn];
ll sub[maxn][maxn];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vll s(n), t(m);
  for (long long i = (long long)(0); i < (long long)(n); ++i) cin >> s[i];
  for (long long i = (long long)(0); i < (long long)(m); ++i) cin >> t[i];
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    for (long long j = (long long)(0); j < (long long)(m); ++j) {
      if (s[i] == t[j]) {
        (dp[i + 1][j + 1] = sub[i][j] + 1) %= MOD;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      (sub[i + 1][j + 1] =
           (sub[i][j + 1] + sub[i + 1][j] - sub[i][j] + dp[i + 1][j + 1]) %
           MOD) %= MOD;
    }
  }
  ll ans = (sub[n][m] + 1) % MOD;
  cout << ans << endl;
}
