#include <bits/stdc++.h>
using namespace std;
const long long int p = 1000000007;
long long int f[2001][2001];
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[i][j] = (f[i][j - 1] + f[i - 1][j] +
                 (s[i - 1] == t[j - 1] ? 1 : -f[i - 1][j - 1])) %
                p;
    }
  }
  cout << 1 + f[n][m] << endl;
  return 0;
}
