#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const long long M = 10000007;
long long sum[maxn << 2];
int son[maxn << 2];
int pos[maxn];
long long p[maxn];
void pushup(int rt) {
  sum[rt] = sum[rt << 1] * p[son[rt << 1 | 1]] + sum[rt << 1 | 1];
  son[rt] = son[rt << 1] + son[rt << 1 | 1];
}
void update(int p, int val, int sgn, int l, int r, int rt) {
  if (l == r) {
    sum[rt] += val;
    son[rt] += sgn;
    return;
  }
  int m = l + r >> 1;
  if (p <= m)
    update(p, val, sgn, l, m, rt << 1);
  else
    update(p, val, sgn, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  p[0] = 1;
  long long h = 0, s = 0;
  for (int i = 1, j; i <= n; i++) {
    scanf("%d", &j);
    h = h * M + j;
    p[i] = p[i - 1] * M;
    s += p[i - 1];
  }
  for (int i = 0, j; i < m; i++) {
    scanf("%d", &j);
    pos[j] = i;
  }
  memset(sum, 0, sizeof(sum));
  memset(son, 0, sizeof(son));
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    update(pos[i], i, 1, 0, m - 1, 1);
    if (i > n) update(pos[i - n], -(i - n), -1, 0, m - 1, 1);
    if (i >= n) {
      int d = i - n;
      if (sum[1] - d * s == h) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
