#include <bits/stdc++.h>
long long res[2000][2000];
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] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (j != 0) res[i][j] = res[i][j - 1];
      if (T[j] == S[i]) {
        for (int k = 0; k < i; k++) {
          if (j != 0) res[i][j] += res[k][j - 1];
        }
        res[i][j] += 1;
        res[i][j] %= mod;
      }
    }
  }
  long long r = 0;
  for (int i = 0; i < N; i++) {
    r += res[i][M - 1];
  }
  printf("%d", (r + 1) % mod);
}
