#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int i, j;
  int s[2003], t[2003];
  for (i = 0; i < n; i++) scanf("%d", &s[i]);
  for (i = 0; i < m; i++) scanf("%d", &t[i]);
  long long int p = 1000000007;
  long long int dp[2003][2003];
  for (i = 0; i < 2003; i++)
    for (j = 0; j < 2003; j++) dp[i][j] = 0;
  for (i = 0; i < 2003; i++) dp[i][0] = dp[0][i] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= p;
      }
      dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      dp[i + 1][j + 1] %= p;
    }
  }
  printf("%lld\n", dp[n][m]);
  return 0;
}
