#include <bits/stdc++.h>
using namespace std;
const int b = 103;
const int mod = 1e9 + 7;
const int N = 200000 + 10;
int t[N * 4], size[N * 4], pos[N], POW[N];
int n, m, flag = 0;
int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
void add(int l, int r, int v, int k, int p) {
  if (l == r) {
    t[k] += v;
    size[k] += v > 0 ? 1 : -1;
    return;
  }
  int mid = (l + r) >> 1;
  if (p > mid)
    add(mid + 1, r, v, k * 2 + 1, p);
  else
    add(l, mid, v, k * 2, p);
  size[k] = size[k * 2] + size[k * 2 + 1];
  t[k] = (1ll * t[k * 2] * POW[size[k * 2 + 1]] + t[k * 2 + 1]) % mod;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    flag = (1ll * flag * b + x) % mod;
  }
  POW[0] = 1;
  for (int i = 1; i <= m; ++i) {
    POW[i] = 1ll * b * POW[i - 1] % mod;
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  for (int i = 1; i <= n; ++i) {
    add(1, m, i, 1, pos[i]);
  }
  int ans = 0, res = 0;
  int tmp = 1ll * (POW[n] - 1) * qpow(b - 1, mod - 2) % mod;
  if (t[1] == flag) ans++;
  for (int i = n + 1; i <= m; ++i) {
    add(1, m, -(i - n), 1, pos[i - n]);
    add(1, m, i, 1, pos[i]);
    res = (res + tmp) % mod;
    int q = (t[1] - res) > 0 ? t[1] - res : (t[1] - res) % mod + mod;
    if (q == flag) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
