#include <bits/stdc++.h>
int tmp, cnt, n, m, b[200007], a[200007];
long long p, plus;
struct node {
  int num;
  long long h;
} st[200007 * 4];
inline long long fast(int a, int b) {
  long long tmp = 1, now = a;
  while (b) {
    if (b % 2) tmp = (tmp * now) % 1000000007;
    now = (now * now) % 1000000007;
    b /= 2;
  }
  return tmp;
}
void modify(int id, int l, int r, int pos, int val) {
  if (l == r) {
    if (val) {
      st[id] = {1, val};
    } else {
      st[id] = {0, 0};
    }
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    modify(id * 2, l, mid, pos, val);
  else
    modify(id * 2 + 1, mid + 1, r, pos, val);
  st[id].num = st[id * 2].num + st[id * 2 + 1].num;
  st[id].h = (st[id * 2].h +
              (st[id * 2 + 1].h * fast(200007, st[id * 2].num)) % 1000000007) %
             1000000007;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    p = (p * 200007 + a[i]) % 1000000007;
    plus = (plus * 200007 + 1) % 1000000007;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &tmp);
    b[tmp] = i;
  }
  for (int i = 1; i <= n; i++) {
    modify(1, 1, m, b[i], i);
  }
  if (p == st[1].h) cnt++;
  for (int d = 1; d <= m - n; d++) {
    modify(1, 1, m, b[d], 0);
    modify(1, 1, m, b[n + d], n + d);
    p = (p + plus) % 1000000007;
    if (p == st[1].h) cnt++;
  }
  printf("%d\n", cnt);
}
