#include <bits/stdc++.h>
const int N_MAX = 2000, M_MAX = 2000, A = 1e9 + 7;
int n, m;
int s[N_MAX], t[M_MAX];
int su[N_MAX][M_MAX];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &t[i]);
  }
  su[0][0] = static_cast<int>(s[0] == t[0]);
  for (int i = 1; i < n; i++) {
    su[i][0] = su[i - 1][0] + static_cast<int>(s[i] == t[0]);
  }
  for (int i = 1; i < m; i++) {
    su[0][i] = su[0][i - 1] + static_cast<int>(s[0] == t[i]);
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      int a = (s[i] == t[j]) ? (su[i - 1][j - 1] + 1) : 0;
      su[i][j] = (static_cast<long>(su[i - 1][j]) + su[i][j - 1] -
                  su[i - 1][j - 1] + a) %
                 A;
    }
  }
  int ans = (su[n - 1][m - 1] + 1) % A;
  printf("%d\n", ans);
}
