#include <bits/stdc++.h>
using namespace std;
const int P = 10000007;
struct node {
  int l, r, num;
  unsigned int sum;
} tree[200005 * 4];
unsigned int pw[200005], h, add;
int n, m;
int c[200005];
void init() {
  int i, j;
  scanf("%d%d", &n, &m);
  pw[0] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &j);
    h = h * P + j;
    add = add * P + 1;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &j);
    pw[i] = pw[i - 1] * P;
    c[j] = i;
  }
}
void build(int l, int r, int d) {
  tree[d].l = l;
  tree[d].r = r;
  tree[d].num = 0;
  if (l - r) {
    int mid = (l + r) / 2;
    build(l, mid, (d * 2 + 1));
    build(mid + 1, r, (d * 2 + 2));
  }
}
void update(int x, int v, int d) {
  if (tree[d].l == tree[d].r) {
    if (v < 0)
      tree[d].num--;
    else
      tree[d].num++;
    tree[d].sum += v;
  } else {
    int mid = (tree[d].l + tree[d].r) / 2;
    if (mid >= x)
      update(x, v, (d * 2 + 1));
    else
      update(x, v, (d * 2 + 2));
    tree[d].num = tree[(d * 2 + 1)].num + tree[(d * 2 + 2)].num;
    tree[d].sum = tree[(d * 2 + 1)].sum * pw[tree[(d * 2 + 2)].num] +
                  tree[(d * 2 + 2)].sum;
  }
}
void solve() {
  int i, ans = 0;
  for (i = 1; i < n; i++) update(c[i], i, 0);
  for (i = n; i <= m; i++) {
    update(c[i], i, 0);
    if (tree[0].sum == h) ans++;
    update(c[i - n + 1], -(i - n + 1), 0);
    h += add;
  }
  cout << ans << endl;
}
int main() {
  init();
  build(0, m, 0);
  solve();
  return 0;
}
