#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
ll power(ll base, ll exponent, ll module) {
  if (exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if (exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}
ll inverse(ll x) { return power(x, mod - 2, mod); }
ll gcd(ll a, ll b) {
  if (a < b) gcd(b, a);
  ll r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}
struct combination {
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for (int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};
const int inf = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (ll i = 0; i < (n); ++i) cin >> s[i];
  for (ll i = 0; i < (m); ++i) cin >> t[i];
  vector<vector<ll>> dp = vector<vector<ll>>(n + 1, vector<ll>(m + 1, 0));
  vector<vector<ll>> cum = vector<vector<ll>>(n + 1, vector<ll>(m + 1, 0));
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (m); ++j) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (cum[i][j] + 1) % mod;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      cum[i + 1][j + 1] =
          (cum[i + 1][j] + cum[i][j + 1] - cum[i][j] + dp[i + 1][j + 1]) % mod;
    }
  }
  cout << cum[n][m] + 1 << endl;
  return 0;
}
