#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], pos_b[200005];
int p = 9357;
unsigned long long hash_a, delta = 1, res[200005];
int n, m;
void init() {
  res[0] = 1;
  for (int i = 1; i <= m; ++i) {
    res[i] = res[i - 1] * p;
  }
  for (int i = 1; i < n; ++i) delta += res[i];
  for (int i = 1; i <= n; ++i) {
    hash_a += a[i] * res[i - 1];
  }
}
struct segmenttree {
  struct node {
    unsigned long long val;
    int num;
  } tree[200005 << 2];
  void pushup(int id) {
    tree[id].num = tree[id << 1].num + tree[id << 1 | 1].num;
    tree[id].val =
        tree[id << 1].val + (tree[id << 1 | 1].val * res[tree[id << 1].num]);
  }
  void build() {
    for (int i = 0; i < 200005 << 2; ++i) tree[i].val = tree[i].num = 0;
  }
  void update(int idx, int v, int l = 1, int r = m, int id = 1) {
    if (l == r) {
      tree[id].val = v;
      tree[id].num = 1;
      return;
    }
    int mid = (l + r) >> 1;
    if (idx <= mid) update(idx, v, l, mid, id << 1);
    if (idx > mid) update(idx, v, mid + 1, r, id << 1 | 1);
    pushup(id);
  }
  void clean(int idx, int l = 1, int r = m, int id = 1) {
    if (l == r) {
      tree[id].val = 0;
      tree[id].num = 0;
      return;
    }
    int mid = (l + r) >> 1;
    if (idx <= mid) clean(idx, l, mid, id << 1);
    if (idx > mid) clean(idx, mid + 1, r, id << 1 | 1);
    pushup(id);
  }
} seg;
int main() {
  int ans = 0;
  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]);
    pos_b[b[i]] = i;
  }
  init();
  seg.build();
  for (int i = 1; i < n; ++i) {
    seg.update(pos_b[i], i);
  }
  for (int i = n; i <= m; ++i) {
    seg.update(pos_b[i], i);
    if (i != n) seg.clean(pos_b[i - n]);
    if (seg.tree[1].val == hash_a) ans++;
    hash_a += delta;
  }
  printf("%d\n", ans);
  return 0;
}
