#include <bits/stdc++.h>
using namespace std;
template <class T>
void checkmin(T &t, T x) {
  if (x < t) t = x;
}
template <class T>
void checkmax(T &t, T x) {
  if (x > t) t = x;
}
const int N = 200005;
const unsigned long long magic = 1000000007;
int n, m;
int a[N];
int b[N];
int size[N * 4];
int pos[N];
unsigned long long key[N * 4];
unsigned long long Pow[N];
void merge(int p) {
  size[p] = size[p * 2] + size[p * 2 + 1];
  key[p] = key[p * 2] * Pow[size[p * 2 + 1]] + key[p * 2 + 1];
}
void insert(int p, int i, int x, int l, int r) {
  if (l == r) {
    key[p] = x;
    size[p] = 1;
    return;
  }
  int mid = (l + r) / 2;
  if (i <= mid) {
    insert(p * 2, i, x, l, mid);
  } else {
    insert(p * 2 + 1, i, x, mid + 1, r);
  }
  merge(p);
}
void erase(int p, int i, int l, int r) {
  if (l == r) {
    size[p] = key[p] = 0;
    return;
  }
  int mid = (l + r) / 2;
  if (i <= mid) {
    erase(p * 2, i, l, mid);
  } else {
    erase(p * 2 + 1, i, mid + 1, r);
  }
  merge(p);
}
int main() {
  scanf("%d%d", &n, &m);
  unsigned long long hash = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    hash = hash * magic + a[i];
  }
  Pow[0] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
    Pow[i] = Pow[i - 1] * magic;
  }
  unsigned long long s = 0;
  for (int i = 0; i < n; i++) {
    s += Pow[i];
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    insert(1, pos[i], i, 1, m);
    if (i > n) {
      erase(1, pos[i - n], 1, m);
    }
    int d = i - n;
    if (d >= 0 && key[1] == hash + d * s) {
      ans++;
    }
  }
  cout << ans << endl;
}
