#include <bits/stdc++.h>
using namespace std;
const long long maxm = 2e5 + 5;
const long long p = 1331;
long long a[maxm];
long long b[maxm];
long long pos[maxm];
unsigned long long base[maxm];
unsigned long long temp;
unsigned long long sum;
long long n, m;
unsigned long long A[maxm << 2];
long long Sum[maxm << 2];
void pushup(long long node) {
  Sum[node] = Sum[node * 2] + Sum[node * 2 + 1];
  A[node] = A[node * 2] * base[Sum[node * 2 + 1]] + A[node * 2 + 1];
}
void update(long long x, long long val, long long l, long long r,
            long long node) {
  if (l == r) {
    Sum[node] = (val != 0);
    A[node] = val;
    return;
  }
  long long mid = (l + r) / 2;
  if (x <= mid)
    update(x, val, l, mid, node * 2);
  else
    update(x, val, mid + 1, r, node * 2 + 1);
  pushup(node);
}
signed main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  base[0] = 1;
  for (long long i = 1; i <= n; i++) {
    base[i] = base[i - 1] * p;
    sum += base[i - 1];
  }
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    temp = temp * p + a[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    update(pos[i], i, 1, m, 1);
  }
  if (A[1] == temp) {
    ans++;
  }
  for (long long i = n + 1; i <= m; i++) {
    update(pos[i - n], 0, 1, m, 1);
    update(pos[i], i, 1, m, 1);
    if (A[1] == sum * (i - n) + temp) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
