#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 18;
const unsigned long long seed = 1000003;
unsigned long long cnt[MAXN << 2];
unsigned long long sum[MAXN << 2];
unsigned long long bin[MAXN << 2];
int pos[MAXN << 2];
void Insert(int pos, unsigned long long v, unsigned long long c, int L, int R,
            int idx) {
  if (L == R) {
    cnt[idx] += c;
    sum[idx] += v;
    return;
  }
  int mid = (L + R) >> 1;
  if (pos <= mid)
    Insert(pos, v, c, L, mid, idx << 1);
  else
    Insert(pos, v, c, mid + 1, R, idx << 1 | 1);
  cnt[idx] = cnt[idx << 1] + cnt[idx << 1 | 1];
  sum[idx] = sum[idx << 1] * bin[cnt[idx << 1 | 1]] + sum[idx << 1 | 1];
}
void output(int l, int r, int idx) {
  if (l == r) {
    cout << idx << " --> " << cnt[idx] << " " << sum[idx] << endl;
    return;
  }
  int mid = (l + r) >> 1;
  output(l, mid, idx << 1);
  output(mid + 1, r, idx << 1 | 1);
}
int main() {
  memset(cnt, 0, sizeof(cnt));
  memset(sum, 0, sizeof(sum));
  unsigned long long sum_base = 0, sum_bin = 0;
  int n, m;
  cin >> n >> m;
  bin[0] = 1;
  for (int i = 1, tmp; i <= n; i++) {
    scanf("%d", &tmp);
    sum_base = sum_base * seed + tmp;
    bin[i] = bin[i - 1] * seed;
    sum_bin += bin[i - 1];
  }
  for (int i = 1, tmp; i <= m; i++) {
    scanf("%d", &tmp);
    pos[tmp] = i;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    Insert(pos[i], i, 1, 1, m, 1);
    if (i > n) {
      Insert(pos[i - n], -(i - n), -1, 1, m, 1);
    }
    if (i >= n) {
      if (sum[1] - sum_bin * (i - n) == sum_base) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
