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