#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> ss;
  vector<long long> ts;
  ss.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> ss.at(i);
  }
  ts.resize(m);
  for (long long i = 0; i < m; ++i) {
    cin >> ts.at(i);
  }
  vector<vector<long long> > dp;
  dp.resize(n + 1);
  for (long long i = 0; i <= n; ++i) {
    if (i < n) {
      dp.at(i).resize(m + 1, 0);
      dp.at(i).at(m) = 1;
    } else {
      dp.at(i).resize(m + 1, 1);
    }
  }
  for (long long i = n - 1; i >= 0; --i) {
    for (long long j = m - 1; j >= 0; --j) {
      if (ss.at(i) == ts.at(j)) {
        dp.at(i).at(j) = dp.at(i + 1).at(j) + dp.at(i).at(j + 1);
      } else {
        dp.at(i).at(j) =
            dp.at(i + 1).at(j) + dp.at(i).at(j + 1) - dp.at(i + 1).at(j + 1);
      }
      dp.at(i).at(j) %= MOD;
    }
  }
  cout << dp.at(0).at(0) << endl;
  return 0;
}
