#include <bits/stdc++.h>
using namespace std;
unsigned long long PW[200010];
unsigned long long a_value;
struct node {
  unsigned long long v;
  int tot;
  friend node operator+(const node &a, const node &b) {
    node ret;
    ret.tot = a.tot + b.tot;
    ret.v = a.v * PW[b.tot] + b.v;
    return ret;
  }
} tree[200010 << 2];
int a[200010], b[200010];
int pos[200010];
int n, m;
int ans;
void ins(int p, int tl, int tr, int k, int v) {
  if (tl == tr) {
    if (v == 1) {
      tree[p].tot = 1;
      tree[p].v = b[k] + 17;
    } else {
      tree[p].tot = 0;
      tree[p].v = 0;
    }
    return;
  }
  int m = (tl + tr) >> 1;
  if (k <= m)
    ins(p << 1, tl, m, k, v);
  else
    ins((p << 1) + 1, m + 1, tr, k, v);
  tree[p] = tree[p << 1] + tree[(p << 1) + 1];
}
int main() {
  PW[0] = 1;
  for (int i = 1; i < 200010; i++) PW[i] = PW[i - 1] * 1307;
  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);
  for (int i = 1; i <= m; i++) pos[b[i]] = i;
  a_value = 0;
  for (int i = 1; i <= n; i++) a_value = a_value * 1307 + a[i] + 17;
  unsigned long long dx = 0;
  for (int i = 0; i < n; i++) dx += PW[i];
  for (int i = 1; i < n; i++) ins(1, 1, m, pos[i], 1);
  int ans = 0;
  for (int d = 0; d <= m - n; d++) {
    ins(1, 1, m, pos[n + d], 1);
    if (tree[1].v == a_value) ++ans;
    a_value += dx;
    ins(1, 1, m, pos[1 + d], -1);
  }
  printf("%d\n", ans);
  return 0;
}
