#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int PRI = 119993;
int ha[4 * MAXN], cnt[4 * MAXN];
int A[MAXN], B[MAXN], W[MAXN];
int n, m;
int jie[MAXN], hash_value, inc_value;
void init() {
  scanf("%d%d", &n, &m);
  hash_value = 0;
  inc_value = 0;
  jie[0] = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", A + i);
    hash_value = hash_value * PRI + A[i];
    inc_value = inc_value * PRI + 1;
    jie[i + 1] = jie[i] * PRI;
  }
  for (int j = 0; j < m; ++j) {
    scanf("%d", B + j);
    W[B[j]] = j + 1;
  }
}
void ins(int x, int y, int h, int pos, int val, int add) {
  if (pos < x || y < pos) return;
  if (x == y) {
    if (add == 1)
      ha[h] = val;
    else
      ha[h] = 0;
    cnt[h] += add;
    return;
  }
  int mid = (x + y) >> 1;
  ins(x, mid, 2 * h + 1, pos, val, add);
  ins(mid + 1, y, 2 * h + 2, pos, val, add);
  cnt[h] = cnt[2 * h + 1] + cnt[2 * h + 2];
  ha[h] = jie[cnt[2 * h + 2]] * ha[2 * h + 1] + ha[2 * h + 2];
}
void solve() {
  int res = 0;
  for (int i = 1; i <= m; ++i) {
    ins(1, m, 0, W[i], i, 1);
    if (i > n) {
      ins(1, m, 0, W[i - n], i - n, -1);
      hash_value += inc_value;
    }
    res += hash_value == ha[0];
  }
  printf("%d\n", res);
}
int main() {
  init();
  solve();
  return 0;
}
