#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, T = 2;
int MOD[T] = {1000000007, 1000000009}, Base[T] = {1000003, 1000003};
int a[N], b[N], p[N], pw[N][2], seg[N << 2][T], Cnt[N << 2], Hash[T], D[T], n,
    m;
void change(int l, int r, int L = 0, int R = m, int id = 1) {
  if (r <= L || R <= l) return;
  if (l <= L && R <= r) {
    if (Cnt[id])
      for (int j = 0; j < T; j++) seg[id][j] = 0;
    else
      for (int j = 0; j < T; j++) seg[id][j] = b[l];
    Cnt[id] ^= 1;
    return;
  }
  int mid = (L + R) >> 1;
  change(l, r, L, mid, id << 1);
  change(l, r, mid, R, id << 1 | 1);
  Cnt[id] = Cnt[id << 1] + Cnt[id << 1 | 1];
  for (int j = 0; j < T; j++)
    seg[id][j] = (1ll * seg[id << 1][j] * pw[Cnt[id << 1 | 1]][j] +
                  seg[id << 1 | 1][j]) %
                 MOD[j];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  fill(pw[0], pw[0] + T, 1);
  for (int j = 0; j < T; j++)
    for (int i = 1; i < N; i++)
      pw[i][j] = (1ll * pw[i - 1][j] * Base[j]) % MOD[j];
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  for (int i = 0; i < m; i++) cin >> b[i], b[i]--, p[b[i]] = i;
  for (int j = 0; j < T; j++)
    for (int i = 0; i < n; i++)
      Hash[j] = (1ll * Hash[j] * Base[j] + a[i]) % MOD[j],
      D[j] = (1ll * D[j] * Base[j] + 1) % MOD[j];
  int ans = 0;
  for (int i = 0; i < m; i++) {
    change(p[i], p[i] + 1);
    if (i >= n) change(p[i - n], p[i - n] + 1);
    if (i >= n - 1) {
      bool flag = 1;
      for (int j = 0; j < T; j++)
        if (seg[1][j] != (Hash[j] + 1ll * D[j] * (i - n + 1)) % MOD[j])
          flag = 0;
      ans += flag;
    }
  }
  cout << ans << "\n";
  return 0;
}
