#include <bits/stdc++.h>
long long ago;
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
  if (!b) return 1;
  if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
  return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 2e5 + 10;
const long long int INF = 8e18;
const long long int MOD[3] = {1000000007, 998244353, 1000000021};
long long int n, m, A[MAXN], B[MAXN], seg[MAXN << 2][3], cnt[MAXN << 2], one[3],
    t[3], base[MAXN][3], ind[MAXN], ans;
void modify(int id, int l, int r, int ind) {
  if (ind < l || r <= ind) return;
  if (r - l == 1) {
    if (cnt[id])
      seg[id][0] = seg[id][1] = seg[id][2] = cnt[id] = 0;
    else
      seg[id][0] = seg[id][1] = seg[id][2] = B[l], cnt[id] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  modify(2 * id, l, mid, ind);
  modify(2 * id + 1, mid, r, ind);
  for (int i = 0; i < 3; i++) {
    seg[id][i] =
        (seg[2 * id][i] + base[cnt[2 * id]][i] * seg[2 * id + 1][i] % MOD[i]) %
        MOD[i];
  }
  cnt[id] = cnt[2 * id] + cnt[2 * id + 1];
}
void print(int id, int l, int r) {
  cout << seg[id][0] << ' ' << l << ' ' << r << '\n';
  if (r - l == 1) return;
  int mid = (l + r) >> 1;
  print(2 * id, l, mid);
  print(2 * id + 1, mid, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> B[i];
    ind[B[i]] = i;
  }
  base[0][0] = base[0][1] = base[0][2] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    for (int j = 0; j < 3; j++) {
      base[i][j] = base[i - 1][j] * n % MOD[j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      one[j] = (one[j] * n % MOD[j] + 1) % MOD[j];
      t[j] = (t[j] + A[i] * base[i][j] % MOD[j]) % MOD[j];
    }
  }
  for (long long int i = 1; i < n; i++) {
    modify(1, 0, m, ind[i]);
  }
  for (long long int i = n; i <= m; i++) {
    modify(1, 0, m, ind[i]);
    bool flag = true;
    for (int j = 0; j < 3; j++) {
      flag &= t[j] == (seg[1][j] + MOD[j] - one[j] * (i - n) % MOD[j]) % MOD[j];
    }
    ans += flag;
    modify(1, 0, m, ind[i - n + 1]);
  }
  cout << ans << '\n';
  return 0;
}
