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