#include <bits/stdc++.h>
using namespace std;
const int N = 200050;
const int MAGIC = int(1e9) + 7;
int n, m, a[N], b[N], len[N << 2], sum[N << 2], pos[N];
int fac[N], pre[N];
inline void pushUp(int rt) {
  len[rt] = len[rt << 1] + len[rt << 1 | 1];
  sum[rt] = sum[rt << 1] * fac[len[rt << 1 | 1]] + sum[rt << 1 | 1];
}
void build(int l, int r, int rt) {
  sum[rt] = len[rt] = 0;
  if (l == r) {
    if (b[l] <= n) sum[rt] = b[l], len[rt] = 1;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
void update(int p, int add, int l, int r, int rt) {
  if (l == r) {
    if (add == 1)
      sum[rt] = b[l], len[rt] = 1;
    else
      sum[rt] = len[rt] = 0;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(p, add, l, m, rt << 1);
  else
    update(p, add, m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * MAGIC;
  pre[0] = fac[0];
  for (int i = 1; i < N; i++) pre[i] = pre[i - 1] + fac[i];
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
  }
  build(1, m, 1);
  int hasha = 0;
  for (int i = 1; i <= n; i++) hasha = hasha * MAGIC + a[i];
  int counts = 0;
  if (hasha == sum[1]) counts = 1;
  for (int i = 2; i + n - 1 <= m; i++) {
    update(pos[i - 1], -1, 1, m, 1);
    update(pos[i + n - 1], 1, 1, m, 1);
    hasha += pre[n - 1];
    if (hasha == sum[1]) counts++;
  }
  printf("%d\n", counts);
  return 0;
}
