#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[2001], T[2001], table[2001 * 2];
int sS[2001], sT[2001];
long long int memo[2001][2001];
long long int func(int spos, int tpos) {
  if (-1 != memo[spos][tpos]) {
    return memo[spos][tpos];
  }
  if (N - 1 == spos) {
    long long int cnt = 0;
    for (int i = tpos; i < M; i++) {
      if (S[spos] == T[i]) {
        cnt++;
      }
    }
    return cnt;
  }
  long long int ret = 0;
  for (int i = tpos; i < M; i++) {
    if (S[spos] == T[i]) {
      if (M - 1 == i) {
        ret++;
      } else {
        ret = (ret + func(spos + 1, i + 1) + 1) % 1000000007;
      }
    }
  }
  ret = (ret + func(spos + 1, tpos)) % 1000000007;
  return memo[spos][tpos] = ret;
}
int main() {
  FILE *fin = NULL, *fout = NULL;
  fin = freopen("input.txt", "r", stdin);
  fout = freopen("output.txt", "w", stdout);
  scanf("%d%d", &N, &M);
  int tail = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", S + i);
    table[tail] = S[i];
    tail++;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", T + i);
    table[tail] = T[i];
    tail++;
  }
  sort(table, table + tail);
  for (int i = 0; i < N; i++) {
    sS[i] = lower_bound(table, table + tail, S[i]) - table;
  }
  for (int i = 0; i < M; i++) {
    sT[i] = lower_bound(table, table + tail, T[i]) - table;
  }
  for (int i = 0; i < 2001; i++) {
    fill(memo[i], memo[i] + 2001, -1);
  }
  printf("%lld", func(0, 0) + 1);
  if (NULL != fin) fclose(fin);
  if (NULL != fout) fclose(fout);
  return 0;
}
