#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int a[maxn], b[maxn], pos[maxn], ans;
unsigned long long hsh, qpow[200020] = {1}, sum;
int n, m;
struct node {
  unsigned long long a, tot;
} tr[maxn << 2];
void pushup(int p) {
  tr[p].tot = tr[p << 1].tot + tr[p << 1 | 1].tot;
  tr[p].a = tr[p << 1].a * qpow[tr[p << 1 | 1].tot] + tr[p << 1 | 1].a;
}
void update(int l, int r, int pos, int p, int k) {
  if (l == r) {
    if (!k)
      tr[p].tot -= 1;
    else
      tr[p].tot += 1;
    tr[p].a = k;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) update(l, mid, pos, p << 1, k);
  if (pos > mid) update(mid + 1, r, pos, p << 1 | 1, k);
  pushup(p);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    hsh = hsh * 23 + a[i];
    qpow[i] = qpow[i - 1] * 23;
    sum += qpow[i - 1];
  }
  for (int i = 1; i <= m; i++) scanf("%lld", &b[i]), pos[b[i]] = i;
  for (int i = 1; i <= m; i++) {
    if (i > n) update(1, m, pos[i - n], 1, 0);
    update(1, m, pos[i], 1, i);
    int d = i - n;
    if (d >= 0 && tr[1].a == d * sum + hsh) ++ans;
  }
  printf("%d", ans);
}
