#include <bits/stdc++.h>
using namespace std;
unsigned long long c[200005], val[200005 * 4], sz[200005 * 4], s1, s2;
int n, m;
int pos[200005];
void build(int l, int r, int id) {
  val[id] = sz[id] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, id << 1);
  build(mid + 1, r, id << 1);
}
void update(int l, int r, int id, int p, int v, int s) {
  if (l == r) {
    val[id] += v;
    sz[id] += s;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update(l, mid, id << 1, p, v, s);
  else
    update(mid + 1, r, id << 1 | 1, p, v, s);
  sz[id] = sz[id << 1] + sz[id << 1 | 1];
  val[id] = val[id << 1] * c[sz[id << 1 | 1]] + val[id << 1 | 1];
}
int main() {
  cin >> n >> m;
  c[0] = 1;
  s1 = s2 = 0;
  for (int i = 1; i <= n; i++) {
    unsigned long long a;
    cin >> a;
    c[i] = c[i - 1] * 100007;
    s1 = s1 * 100007 + a;
    s2 = s2 + c[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int a;
    cin >> a;
    pos[a] = i;
  }
  build(1, m, 1);
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    update(1, m, 1, pos[i], i, 1);
    if (i >= n) {
      if (i > n) update(1, m, 1, pos[i - n], n - i, -1);
      unsigned long long d = i - n;
      if (s1 + d * s2 == val[1]) sum++;
    }
  }
  cout << sum << endl;
}
