#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
void print_container(T &container, string delim = " ") {
  bool first = true;
  for (auto &t : container) {
    if (!first) {
      cout << delim;
    }
    first = false;
    cout << t;
  }
  cout << endl;
}
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int((i)) = (0); ((i)) < ((n)); ((i))++) {
    cin >> s[i];
  }
  for (int((i)) = (0); ((i)) < ((m)); ((i))++) {
    cin >> t[i];
  }
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
  dp[0][0] = 1;
  vector<vector<ll>> accum(n + 1, vector<ll>(m + 1, 0));
  for (int(i) = (0); (i) <= (n); (i)++) {
    accum[i][0] = 1;
  }
  for (int(j) = (0); (j) <= (m); (j)++) {
    accum[0][j] = 1;
  }
  for (int(i) = (1); (i) <= (n); (i)++) {
    for (int(j) = (1); (j) <= (m); (j)++) {
      if (s[i - 1] != t[j - 1])
        dp[i][j] = 0;
      else {
        dp[i][j] = accum[i - 1][j - 1];
      }
      accum[i][j] =
          (accum[i - 1][j] + accum[i][j - 1] - accum[i - 1][j - 1] + dp[i][j]) %
          MOD;
    }
  }
  cout << accum[n][m] << endl;
  return 0;
}
