#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int n, m, a[2005], b[2005], ans, f[2005][2005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1]) % p;
      if (a[i] == b[j]) {
        f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1) % p;
      }
    }
  }
  cout << (f[n][m] + 1) % p << endl;
  return 0;
}
