#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
const long long P = 13331;
const long long mod = 999998639;
unsigned long long power[N];
long long a[N], b[N], pos[N];
struct Seg_ment {
  unsigned long long pre, tot;
  long long l, r;
} tree[N << 2];
void push_up(long long id) {
  tree[id].tot = tree[id << 1].tot + tree[id << 1 | 1].tot;
  tree[id].pre = (tree[id << 1].pre * power[tree[id << 1 | 1].tot] +
                  tree[id << 1 | 1].pre) %
                 mod;
}
void build(long long l, long long r, long long id) {
  tree[id].l = l, tree[id].r = r;
  tree[id].pre = 0;
  if (l == r) return;
  long long mid = l + r >> 1;
  build(l, mid, id << 1);
  build(mid + 1, r, id << 1 | 1);
  push_up(id);
}
void update(long long id, long long pos, long long val) {
  if (tree[id].l == tree[id].r) {
    if (!val)
      tree[id].tot -= 1;
    else
      tree[id].tot += 1;
    tree[id].pre = val;
    return;
  }
  long long mid = tree[id].l + tree[id].r >> 1;
  if (pos <= mid) update(id << 1, pos, val);
  if (pos > mid) update(id << 1 | 1, pos, val);
  push_up(id);
}
void init() {
  power[0] = 1;
  for (long long i = 1; i <= 200000; i++) power[i] = power[i - 1] * P % mod;
}
signed main() {
  std::ios::sync_with_stdio(false);
  init();
  long long n, m, ans = 0;
  cin >> n >> m;
  build(1, m, 1);
  unsigned long long sum = 0, add = 0;
  for (long long i = 1; i <= n; i++)
    cin >> a[i], sum = (sum * P + a[i]) % mod, add += power[i - 1], add %= mod;
  for (long long i = 1; i <= m; i++) cin >> b[i], pos[b[i]] = i;
  for (long long i = 1; i <= m; i++) {
    if (i > n) update(1, pos[i - n], 0);
    update(1, pos[i], i);
    long long cha = i - n;
    if (cha >= 0 && tree[1].pre % mod == (sum + cha * add) % mod) ans++;
  }
  cout << ans << '\n';
  return 0;
}
