#include <bits/stdc++.h>
long long res[2001][2001];
const int mod = 1000000007;
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int *S = new int[N];
  int *T = new int[M];
  for (int i = 0; i < N; i++) {
    scanf("%d", &S[i]);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &T[i]);
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      res[i][j] = 1;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S[i - 1] == T[j - 1]) {
        res[i][j] = res[i - 1][j] + res[i][j - 1];
        res[i][j] %= mod;
      } else {
        res[i][j] = res[i - 1][j] + res[i][j - 1] - res[i - 1][j - 1];
        res[i][j] %= mod;
      }
    }
  }
  printf("%d", res[N][M]);
}
