#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
int qp(int a, ll b) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % 1000000007;
    a = 1ll * a * a % 1000000007;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll invfac[2002];
ll fac[2002];
ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);
int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<ll> s(n);
  vector<ll> t(m);
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  for (int i = 0; i < (int)(m); i++) cin >> t[i];
  vector<vector<ll> > dp(n + 1, vector<ll>(m + 1, 0));
  vector<vector<ll> > sumdp(n + 1, vector<ll>(m + 1, 0));
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (i == 0 && j == 0) {
        if (s[i] == t[j]) {
          dp[i][j] = 1;
        }
        sumdp[i][j] = dp[i][j];
      } else if (i == 0) {
        if (s[i] == t[j]) {
          dp[i][j] = 1;
        }
        sumdp[i][j] = mod_add(sumdp[i][j - 1], dp[i][j]);
      } else if (j == 0) {
        if (s[i] == t[j]) {
          dp[i][j] = 1;
          sumdp[i][j] = 1;
        }
        sumdp[i][j] = mod_add(sumdp[i - 1][j], dp[i][j]);
      } else {
        if (s[i] == t[j]) {
          dp[i][j] = mod_add(sumdp[i - 1][j - 1], 1);
        }
        sumdp[i][j] = mod_add(
            sumdp[i - 1][j] + sumdp[i][j - 1] - sumdp[i - 1][j - 1], dp[i][j]);
      }
    }
  }
  cout << mod_add(sumdp[n - 1][m - 1], 1) << endl;
  return 0;
}
ll mod_pow(ll x, ll r) {
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % 1000000007;
  else if (r % 2 == 0) {
    ll t = mod_pow(x, r / 2) % 1000000007;
    return t * t % 1000000007;
  } else {
    ll t = mod_pow(x, r / 2) % 1000000007;
    ll k = t * t % 1000000007;
    return k * x % 1000000007;
  }
}
ll mod_add(ll a, ll b) { return (a + b) % 1000000007; }
ll mod_mul(ll a, ll b) { return (a * b) % 1000000007; }
ll mod_div(ll a, ll b) { return mod_mul(a, mod_pow(b, 1000000007 - 2)); }
void make_fact(ll n) {
  fac[0] = 1;
  for (int i = 0; i < (int)(n); i++) {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}
void make_invfact(ll n) {
  invfac[n] = mod_pow(fac[n], 1000000007 - 2);
  for (int i = n - 1; i >= 0; i--) {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}
