#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  long long ans = 0LL;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  vector<long long> dp0(n + 1, 0);
  vector<long long> dp1(n + 1, 1);
  dp0[0] = 1;
  dp1[1] = 1;
  for (long long i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (t[i] == s[j]) {
        dp0[j + 1] = dp0[j] + dp1[j + 1];
      } else {
        dp0[j + 1] = dp0[j] + dp1[j + 1] - dp1[j];
      }
      dp0[j + 1] %= 1000000007;
    }
    for (long long j = 0; j < n; j++) dp1[j + 1] = dp0[j + 1];
  }
  cout << dp0[n] << endl;
  return 0;
}
