#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long mod = 1000696969;
long long a[N], pos[N], pw[N], hsh[4 * N], cnt[4 * N], n, m;
void upd(int p, int x, int l = 1, int r = m + 1, int id = 1) {
  if (r - l == 1) {
    hsh[id] = x * a[l];
    cnt[id] = x;
    return;
  }
  int md = (l + r) >> 1;
  if (p < md)
    upd(p, x, l, md, id << 1);
  else
    upd(p, x, md, r, id << 1 | 1);
  hsh[id] = (hsh[id << 1] + hsh[id << 1 | 1] * pw[cnt[id << 1]]) % mod;
  cnt[id] = cnt[id << 1] + cnt[id << 1 | 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pw[0] = 1;
  for (int i = 1; i < N; i++) pw[i] = 1399LL * pw[i - 1] % mod;
  cin >> n >> m;
  long long h = 0, hp = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    h = (h + x * pw[i]) % mod;
    hp = (hp + pw[i]) % mod;
  }
  for (int i = 1; i <= m; i++) cin >> a[i], pos[a[i]] = i;
  int ans = 0;
  for (int i = 1; i <= n; i++) upd(pos[i], 1);
  if (h == hsh[1]) ans++;
  for (int i = n + 1; i <= m; i++) {
    upd(pos[i - n], 0);
    upd(pos[i], 1);
    h = (h + hp) % mod;
    if (h == hsh[1]) ans++;
  }
  cout << ans;
  return 0;
}
