#include <bits/stdc++.h>
using namespace std;
const long long P = 131, mod1 = 998244353, mod2 = 1e9 + 7;
const int N = 2e5 + 10;
long long n, m, ans;
long long a[N], b[N], pos[N];
long long bit1[N], bit2[N], val1, val2, sum1, sum2;
long long v1[N << 2], v2[N << 2], sz[N << 2];
void modify(int x, int l, int r, int pos, int val, int ff) {
  if (l == r) {
    v1[x] += val * ff % mod1;
    v2[x] += val * ff % mod2;
    sz[x] += ff;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(x << 1, l, mid, pos, val, ff);
  else
    modify(x << 1 | 1, mid + 1, r, pos, val, ff);
  v1[x] = (v1[x << 1] + v1[x << 1 | 1] * bit1[sz[x << 1]] % mod1) % mod1;
  v2[x] = (v2[x << 1] + v2[x << 1 | 1] * bit2[sz[x << 1]] % mod2) % mod2;
  sz[x] = sz[x << 1] + sz[x << 1 | 1];
}
int main() {
  cin >> n >> m;
  bit1[0] = bit2[0] = 1;
  for (int i = 1; i <= m; i++)
    bit1[i] = bit1[i - 1] * P % mod1, bit2[i] = bit2[i - 1] * P % mod2;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    val1 = (val1 + a[i] * bit1[i - 1] % mod1) % mod1;
    val2 = (val2 + a[i] * bit2[i - 1] % mod2) % mod2;
    sum1 = (sum1 + bit1[i - 1]) % mod1;
    sum2 = (sum2 + bit2[i - 1]) % mod2;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    pos[b[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    modify(1, 1, m, pos[i], i, 1);
    if (i >= n) {
      if (v1[1] == (val1 + (i - n) * sum1 % mod1) % mod1 &&
          v2[1] == (val2 + (i - n) * sum2 % mod2) % mod2)
        ++ans;
      modify(1, 1, m, pos[i - n + 1], i - n + 1, -1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
