#include <bits/stdc++.h>
using namespace std;
long long kMod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> t.at(i);
  }
  vector<vector<long long>> sum(n, vector<long long>(m));
  sum.at(0).at(0) = (int)(s.at(0) == t.at(0)) + 1;
  for (int x = 1; x < n; x++) {
    sum.at(x).at(0) = (int)(s.at(x) == t.at(0)) + sum.at(x - 1).at(0);
  }
  for (int y = 1; y < m; y++) {
    sum.at(0).at(y) = (int)(s.at(0) == t.at(y)) + sum.at(0).at(y - 1);
  }
  for (int x = 1; x < n; x++) {
    for (int y = 1; y < m; y++) {
      if (s.at(x) == t.at(y)) {
        sum.at(x).at(y) = sum.at(x - 1).at(y - 1);
      }
      sum.at(x).at(y) +=
          sum.at(x - 1).at(y) + sum.at(x).at(y - 1) - sum.at(x - 1).at(y - 1);
      sum.at(x).at(y) %= kMod;
    }
  }
  cout << sum.at(n - 1).at(m - 1) << '\n';
  return 0;
}
