#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200010;
const long long P = 10007;
int n, m;
int a[Maxn], b[Maxn];
long long c[Maxn], cp[Maxn];
long long hasha;
long long p[Maxn];
void getP() {
  p[0] = 1;
  for (int i = 1; i <= m; ++i) p[i] = p[i - 1] * P;
}
void insert(long long c[], long long v, int from) {
  for (int i = from; i <= m; i += (-i & i)) c[i] += v;
}
long long search(long long c[], int k) {
  long long ret = 0;
  for (int i = k; i > 0; i -= (-i & i)) ret += c[i];
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  getP();
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= n; ++i) {
    hasha += p[i - 1] * search(c, a[i]);
    insert(c, 1, a[i]);
  }
  for (int i = 1; i <= m; ++i) {
    int x;
    scanf("%d", &x);
    b[x] = i;
  }
  memset(c, 0, sizeof(c));
  memset(cp, 0, sizeof(cp));
  long long hash = 0;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    hash += p[i - 1] * search(c, b[i]);
    insert(c, 1, b[i]);
    insert(cp, p[i - 1], b[i]);
  }
  if (hash == hasha) ans++;
  for (int i = n + 1; i <= m; ++i) {
    hash += p[i - 1] * search(c, b[i]);
    insert(c, 1, b[i]);
    insert(cp, p[i - 1], b[i]);
    insert(c, -1, b[i - n]);
    insert(cp, -p[i - n - 1], b[i - n]);
    hash -= search(cp, m) - search(cp, b[i - n]);
    if (hash == p[i - n] * hasha) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
