#include <bits/stdc++.h>
int n, m;
int s[2000];
int t[2000];
long int sum[2000][2000];
long int g(int, int);
long int f(int a, int b) {
  if (sum[a][b] >= 0) return sum[a][b];
  if (a >= n || b >= m) return 0;
  long int ans = (f(a + 1, b) + f(a, b + 1)) % 1000000007;
  if (s[a] == t[b])
    ans = (ans + 1) % 1000000007;
  else
    ans = (ans - f(a + 1, b + 1)) % 1000000007;
  sum[a][b] = ans;
  return ans;
}
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      sum[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", s + i);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", t + i);
  }
  printf("%ld\n", f(0, 0) + 1);
  return 0;
}
