#include <bits/stdc++.h>
const int BASE = 1000000007;
int nextSelectS(int selectS[], const int N, int num1) {
  for (int i = 0; i < N; i++) {
    if (selectS[i] == 1) {
      selectS[i] = 0;
      num1--;
    } else {
      selectS[i] = 1;
      return num1 + 1;
    }
  }
  return 0;
}
int match(const int S[], const int selectS[], const int T[], const int N,
          const int M, const int num1) {
  int* const path = (int*)calloc(M, sizeof(int));
  for (int j = 0; j < M; j++) path[j] = 1;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (selectS[i] == 1) {
      const int s = S[i];
      sum = 0;
      for (int j = 0; j < M; j++) {
        if (T[j] == s) {
          const int temp = path[j];
          path[j] = sum;
          sum += temp;
        } else {
          path[j] = sum;
        }
      }
      if (sum == 0) {
        break;
      }
    }
  }
  delete[] path;
  return sum;
}
int main(void) {
  int N;
  int M;
  std::cin >> N >> M;
  int* const S = (int*)calloc(N, sizeof(int));
  int* const T = (int*)calloc(M, sizeof(int));
  int* const selectS = (int*)calloc(N, sizeof(int));
  int* const path = (int*)calloc(M, sizeof(int));
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
    selectS[i] = 0;
  }
  for (int j = 0; j < M; j++) std::cin >> T[j];
  int num1 = 0;
  int count = 1;
  while ((num1 = nextSelectS(selectS, N, num1)) != 0) {
    if (num1 > M) continue;
    count += match(S, selectS, T, N, M, num1);
    count = count % BASE;
  }
  std::cout << count << std::endl;
  return 0;
}
