#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  vector<long long> s(n + 1), t(m + 1);
  for (long long i = 1; i <= n; ++i) scanf("%lld", &s.at(i));
  for (long long i = 1; i <= m; ++i) scanf("%lld", &t.at(i));
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1));
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j)
      dp.at(i).at(j) = dp.at(i - 1).at(j) + dp.at(i).at(j - 1) +
                       (s.at(i) == t.at(j) ? 1 : -dp.at(i - 1).at(j - 1)),
      dp.at(i).at(j) %= 1000000007;
  printf("%lld\n", (dp.at(n).at(m) + 1) % 1000000007);
  return 0;
}
