#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
  int cnt;
  unsigned long long val;
} tree[4 * 200005];
void build(int idx, int l, int r) {
  tree[idx].l = l;
  tree[idx].r = r;
  tree[idx].cnt = 0;
  tree[idx].val = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(idx * 2, l, mid);
  build(idx * 2 + 1, mid + 1, r);
  return;
}
unsigned long long pw[200005];
void update(int idx, int pos, unsigned long long val) {
  if (tree[idx].l == tree[idx].r) {
    tree[idx].val = val;
    if (val == 0)
      tree[idx].cnt = 0;
    else
      tree[idx].cnt = 1;
    return;
  }
  int mid = (tree[idx].l + tree[idx].r) / 2;
  if (pos <= mid)
    update(idx * 2, pos, val);
  else
    update(idx * 2 + 1, pos, val);
  tree[idx].val =
      tree[idx * 2].val * pw[tree[idx * 2 + 1].cnt] + tree[idx * 2 + 1].val;
  tree[idx].cnt = tree[idx * 2].cnt + tree[idx * 2 + 1].cnt;
}
int da[200005];
int db[200005];
int d[200005];
inline unsigned long long add(int *s, int len) {
  unsigned long long res = 0;
  for (int i = 0; i < len; ++i) {
    res *= 9837;
    res += s[i];
  }
  return res;
}
int wz[200005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  pw[0] = 1;
  for (int i = 1; i <= m; i++) pw[i] = pw[i - 1] * 9837;
  for (int i = 0; i < n; i++) scanf("%d", da + i);
  for (int i = 0; i < m; i++) {
    scanf("%d", db + i);
    wz[db[i]] = i;
  }
  build(1, 1, m);
  for (int i = 0; i < n; i++) d[i] = 1;
  unsigned long long temp = add(d, n);
  unsigned long long now = add(da, n);
  int all = 0;
  for (int i = 1; i <= m; i++) {
    if (i <= n) {
      update(1, wz[i] + 1, i);
    } else {
      update(1, wz[i] + 1, i);
      update(1, wz[i - n] + 1, 0);
    }
    if (i >= n) {
      if (tree[1].val == now) all++;
      now += temp;
    }
  }
  cout << all << endl;
}
