#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;
constexpr int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vll s(n), t(m);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < (int)(m); ++i) {
    cin >> t[i];
  }
  ll ans = 1;
  vll cols(n, 0);
  for (int i = 0; i < (int)(n); ++i) {
    ll sum = 0;
    for (int j = 0; j < (int)(m); ++j) {
      ll tmp = s[i] == t[j] ? (1 + sum) % MOD : 0;
      sum = (sum + cols[j]) % MOD;
      cols[j] = (cols[j] + tmp) % MOD;
      ans = (ans + tmp) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
