#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005, tt[6] = {100000007,  100000009, 1000000007,
                                  1000000009, 233333333, 998244353};
struct tree {
  int w, sz;
};
int n, m, ans, ha[6], a[MAXN], b[MAXN], p[MAXN], W[6][MAXN], WW[6][MAXN];
tree t[6][4 * MAXN];
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int Add(int x, int y, int TT) { return x + y < TT ? x + y : x + y - TT; }
void Put(int k, int id, int L, int R, int x, int fl) {
  if (L == R) {
    t[k][id].sz = fl;
    t[k][id].w = (fl ? b[x] : 0);
    return;
  }
  int mid = (L + R) >> 1, ls = id * 2, rs = id * 2 + 1;
  if (x <= mid)
    Put(k, ls, L, mid, x, fl);
  else
    Put(k, rs, mid + 1, R, x, fl);
  t[k][id].sz = t[k][ls].sz + t[k][rs].sz;
  t[k][id].w =
      Add((long long)t[k][ls].w * W[k][t[k][rs].sz] % tt[k], t[k][rs].w, tt[k]);
}
int main() {
  n = read(), m = read();
  for (int i = (1); i <= (n); i++) a[i] = read();
  for (int i = (1); i <= (m); i++) b[i] = read(), p[b[i]] = i;
  for (int k = (0); k <= (5); k++) {
    for (int i = (1); i <= (n); i++)
      ha[k] = ((long long)ha[k] * 233333 + a[i]) % tt[k];
    W[k][0] = 1;
    for (int i = (1); i <= (m); i++)
      W[k][i] = (long long)W[k][i - 1] * 233333 % tt[k];
    WW[k][0] = 1;
    for (int i = (1); i <= (m); i++)
      WW[k][i] = ((long long)WW[k][i - 1] * 233333 + 1) % tt[k];
  }
  for (int k = (0); k <= (5); k++)
    for (int i = (1); i <= (n); i++) Put(k, 1, 1, m, p[i], 1);
  for (int i = (n); i <= (m); i++) {
    ans++;
    for (int k = (0); k <= (5); k++)
      if (t[k][1].w != ha[k]) {
        ans--;
        break;
      }
    for (int k = (0); k <= (5); k++) {
      Put(k, 1, 1, m, p[i + 1 - n], 0);
      Put(k, 1, 1, m, p[i + 1], 1);
      ha[k] = Add(ha[k], WW[k][n - 1], tt[k]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
