#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1000000007;
int main(void) {
  long long n, m;
  cin >> n >> m;
  vector<long long> ss(n);
  for (int i = 0; i < n; i++) cin >> ss[i];
  vector<long long> ts(m);
  for (int i = 0; i < m; i++) cin >> ts[i];
  vector<vector<long long>> sum(n + 5, vector<long long>(m + 5, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long ip = i + 1;
      long long jp = j + 1;
      sum[ip][jp] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
      if (ss[i] == ts[j]) {
        sum[ip][jp] += sum[i][j] + 1;
      }
      sum[ip][jp] %= mod;
    }
  }
  cout << sum[n][m] + 1 << endl;
  return 0;
}
