#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M1 = 998244353, M2 = 1e9 + 7, P1 = 1234567, P2 = 7654321;
int n, m, a[N], b[N], c[N], fac1[N], fac2[N], s1, s2, pre1, pre2;
struct Tree {
  int l, r, num1, num2, len;
} T[N * 4];
void build(int x, int l, int r) {
  T[x].l = l;
  T[x].r = r;
  if (l == r) return;
  int mid = (T[x].l + T[x].r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
}
void insert(int x, int y, int z) {
  T[x].len += z;
  if (T[x].l == T[x].r) {
    if (z == 1)
      T[x].num1 = T[x].num2 = b[y];
    else
      T[x].num1 = T[x].num2 = 0;
    return;
  }
  int mid = (T[x].l + T[x].r) / 2;
  if (y <= mid)
    insert(x * 2, y, z);
  else
    insert(x * 2 + 1, y, z);
  T[x].num1 =
      ((long long)T[x * 2].num1 * fac1[T[x * 2 + 1].len] + T[x * 2 + 1].num1) %
      M1;
  T[x].num2 =
      ((long long)T[x * 2].num2 * fac2[T[x * 2 + 1].len] + T[x * 2 + 1].num2) %
      M2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]), c[b[i]] = i;
  fac1[0] = fac2[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac1[i] = (long long)fac1[i - 1] * P1 % M1;
    fac2[i] = (long long)fac2[i - 1] * P2 % M2;
    s1 = ((long long)s1 * P1 + a[i]) % M1;
    s2 = ((long long)s2 * P2 + a[i]) % M2;
    (pre1 += fac1[i - 1]) %= M1;
    (pre2 += fac2[i - 1]) %= M2;
  }
  build(1, 1, m);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    insert(1, c[i], 1);
    if (i > n) insert(1, c[i - n], -1);
    if (i >= n && T[1].num1 == ((long long)pre1 * (i - n) + s1) % M1 &&
        T[1].num2 == ((long long)pre2 * (i - n) + s2) % M2)
      ans++;
  }
  printf("%d\n", ans);
}
