#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, m, ps[2010][2010];
int main() {
  ios_base::sync_with_stdio(false);
  memset(ps, 0, sizeof ps);
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i and j)
        ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1];
      else
        ps[i][j] = 1;
      if (i != 0 and j != 0 and a[i - 1] == b[j - 1])
        ps[i][j] += ps[i - 1][j - 1];
      ps[i][j] %= mod;
    }
  }
  cout << ps[n][m] << endl;
  return 0;
}
