#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
int n, m, a[2001], b[2001];
long long jp[2001][2001];
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++) {
      jp[i][j] = (jp[i - 1][j] + jp[i][j - 1] - jp[i - 1][j - 1]) % mo;
      if (a[i] == b[j]) jp[i][j] += (jp[i - 1][j - 1] + 1), jp[i][j] %= mo;
    }
  cout << jp[n][m] % mo + 1;
  return 0;
}
