#include <bits/stdc++.h>
using namespace std;
unsigned long long pow1[200000 + 1];
struct Hash {
  int n;
  unsigned long long v;
  Hash(const int _x = 0) : v(_x) { n = !!_x; }
  Hash(const int _n, const unsigned long long _v) : n(_n), v(_v) {}
};
inline Hash operator+(const Hash &a, const Hash &b) {
  return Hash(a.n + b.n, a.v * pow1[b.n] + b.v);
}
inline bool operator==(const Hash &a, const Hash &b) {
  return a.n == b.n && a.v == b.v;
}
struct HashTree {
  int n, pool_n;
  struct HashNode {
    int s, e;
    Hash v;
    HashNode *l, *r;
    void u(int x, int k) {
      if (s == x && e == x)
        v = Hash(k);
      else {
        if (x <= ((s + e) / 2))
          l->u(x, k);
        else
          r->u(x, k);
        v = l->v + r->v;
      }
    }
  } * pool, *root;
  HashNode *alloc(int s, int e) {
    HashNode *x = pool + (pool_n++);
    x->s = s;
    x->e = e;
    if (s != e) {
      int m = (s + e) / 2;
      x->l = alloc(s, m);
      x->r = alloc(m + 1, e);
    } else
      x->l = x->r = NULL;
    return x;
  }
  HashTree(const int &_n) : n(_n) {
    pool = new HashNode[n * 2];
    pool_n = 0;
    root = alloc(0, n - 1);
  }
  inline void u(int x, int k) { root->u(x, k); }
  inline Hash v() { return root->v; }
};
int n, m, a[200000], b[200000], rb[200000], total;
int main() {
  for (int i = 0; i < (200000 + 1); ++i) pow1[i] = i ? pow1[i - 1] * 3511 : 1L;
  scanf("%d%d", &n, &m);
  Hash targ, ones;
  HashTree tree(m);
  for (int i = 0; i < (n); ++i)
    scanf("%d", &a[i]), targ = targ + Hash(a[i]), ones = ones + Hash(1);
  for (int i = 0; i < (m); ++i) scanf("%d", &b[i]), rb[b[i] - 1] = i;
  for (int i = 0; i < (m); ++i) {
    tree.u(rb[i], i + 1);
    if (i >= n) {
      tree.u(rb[i - n], 0);
      targ = Hash(targ.n, targ.v + ones.v);
    }
    if (tree.v() == targ) ++total;
  }
  printf("%d\n", total);
  return 0;
}
