#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
int BIT[202020];
int lb(int x) { return x & (-x); }
void modify_BIT(int p, int d) {
  for (int i = p; i < 202020; i += lb(i)) BIT[i] += d;
}
int query_BIT(int p) {
  int ret = 0;
  for (int i = p; i; i -= lb(i)) ret += BIT[i];
  return ret;
}
const int BS = 999983;
const int mods[3] = {1000000007LL, 1000000009LL, 100102021};
struct hsvl {
  int v[3];
  hsvl(int vv = 0) {
    for (int i = 0; i < 3; i++) v[i] = vv;
  }
  hsvl operator+(const hsvl& he) const {
    hsvl ret;
    for (int i = 0; i < 3; i++) ret.v[i] = add(he.v[i], v[i], mods[i]);
    return ret;
  }
  hsvl operator-(const hsvl& he) const {
    hsvl ret;
    for (int i = 0; i < 3; i++) ret.v[i] = sub(v[i], he.v[i], mods[i]);
    return ret;
  }
  hsvl operator*(const hsvl& he) const {
    hsvl ret;
    for (int i = 0; i < 3; i++) ret.v[i] = mul(he.v[i], v[i], mods[i]);
    return ret;
  }
  bool operator==(const hsvl& he) const {
    for (int i = 0; i < 3; i++)
      if (v[i] != he.v[i]) return false;
    return true;
  }
  void print() {
    for (int i = 0; i < 3; i++) printf("%d%c", v[i], " \n"[i + 1 == 3]);
  }
};
hsvl st[202020 << 2];
void modify(int no, int l, int r, int p, hsvl d) {
  if (l == r) {
    st[no] = st[no] + d;
    return;
  }
  if (p <= ((l + r) >> 1))
    modify((no << 1), l, ((l + r) >> 1), p, d);
  else
    modify((1 + (no << 1)), ((l + r) >> 1) + 1, r, p, d);
  st[no] = st[(no << 1)] + st[(1 + (no << 1))];
}
hsvl query(int no, int l, int r, int ql, int qr) {
  if (r < ql or l > qr or ql > qr) return hsvl(0);
  if (ql <= l and r <= qr) return st[no];
  return query((no << 1), l, ((l + r) >> 1), ql, qr) +
         query((1 + (no << 1)), ((l + r) >> 1) + 1, r, ql, qr);
}
hsvl bs[202020], bsv;
void build() {
  bsv = hsvl(BS);
  bs[0] = hsvl(1);
  for (int i = 1; i < 202020; i++) bs[i] = bs[i - 1] * bsv;
}
int n, m, a[202020], b[202020];
void init() {
  n = getint();
  m = getint();
  for (int i = 1; i <= n; i++) a[getint()] = i;
  ;
  for (int i = 1; i <= m; i++) b[getint()] = i;
}
void solve() {
  hsvl tar(0);
  for (int i = 1; i <= n; i++) tar = tar + bs[i] * hsvl(a[i]);
  int ans = 0;
  hsvl cur(0);
  for (int i = 1; i <= n; i++) {
    modify(1, 1, m, b[i], bs[i]);
    cur = cur + bs[i];
    modify_BIT(b[i], +1);
  }
  for (int i = 1; i <= n; i++) cur = cur + query(1, 1, m, b[i] + 1, m);
  for (int i = n; i <= m; i++) {
    if (cur == tar * bs[i - n]) ans++;
    if (i == m) break;
    {
      cur = cur - query(1, 1, m, b[i - n + 1] + 1, m);
      int cc = query_BIT(b[i - n + 1]);
      cur = cur - hsvl(cc) * bs[i - n + 1];
      modify_BIT(b[i - n + 1], -1);
      modify(1, 1, m, b[i - n + 1], hsvl(0) - bs[i - n + 1]);
    }
    {
      modify(1, 1, m, b[i + 1], bs[i + 1]);
      modify_BIT(b[i + 1], +1);
      int cc = query_BIT(b[i + 1]);
      cur = cur + hsvl(cc) * bs[i + 1];
      cur = cur + query(1, 1, m, b[i + 1] + 1, m);
    }
  }
  printf("%d\n", ans);
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
