#include <bits/stdc++.h>
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vl a(n), b(m);
  for (ll i = 0; i < ll(n); ++i) cin >> a[i];
  for (ll i = 0; i < ll(m); ++i) cin >> b[i];
  vvi dp(n + 1, vi(m + 1, 0));
  for (ll i = 0; i < ll(n); ++i)
    for (ll j = 0; j < ll(m); ++j) {
      dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      dp[i + 1][j + 1] %= 1000000007ll;
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] += 1 + dp[i][j];
        dp[i + 1][j + 1] %= 1000000007ll;
      }
    }
  cout << (dp[n][m] + 1) % 1000000007ll << endl;
}
