#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
ll dp[2020][2020];
int f[2020];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vll s(n);
  for (ll i = 0; i < (n); i++) {
    cin >> s[i];
  }
  vll t(m);
  for (ll i = 0; i < (m); i++) {
    cin >> t[i];
  }
  for (ll i = 0; i < (2020); i++) {
    dp[i][0] = 1;
    dp[0][i] = 1;
  }
  for (ll i = 0; i < (m); i++) {
    for (ll j = 0; j < (n); j++) {
      if (s[j] == t[i]) {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
        f[j + 1] = 1;
      } else if (f[j + 1]) {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + MOD) % MOD;
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }
  cout << dp[m][n] << endl;
  return 0;
}
