#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010, p = 43;
int n, m, ans, a[maxn], cnt[maxn << 2];
unsigned long long h, sum, base[maxn], node[maxn << 2];
void modify(int k, int l, int r, int p, int v) {
  if (l == r) {
    cnt[k] = !!(node[k] = v);
    return;
  }
  int mid = (l + r) >> 1;
  mid >= p ? modify(k << 1, l, mid, p, v)
           : modify(k << 1 | 1, mid + 1, r, p, v);
  cnt[k] = cnt[k << 1] + cnt[k << 1 | 1];
  node[k] = node[k << 1] + node[k << 1 | 1] * base[cnt[k << 1]];
}
int main() {
  scanf("%d %d", &n, &m), base[0] = 1;
  for (int i = 1; i <= n; i++) {
    base[i] = base[i - 1] * p;
  }
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x), h += x * base[i], sum += base[i];
  }
  for (int i = 0, x; i < m; i++) {
    scanf("%d", &x), a[x - 1] = i;
  }
  for (int i = 0; i < n; i++) {
    modify(1, 0, m - 1, a[i], i + 1);
  }
  ans = (node[1] == h);
  for (int i = n; i < m; i++) {
    modify(1, 0, m - 1, a[i - n], 0), modify(1, 0, m - 1, a[i], i + 1);
    ans += (node[1] == h + (i - n + 1) * sum);
  }
  printf("%d\n", ans);
  return 0;
}
