#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int mod = 2117566807;
const int nmax = 2e5 + 2;
long long bst[4 * nmax];
long long cnt[4 * nmax];
const int bes = 1997293877;
long long bespow[nmax], psam, val;
void updet(int a, int L, int R, int pos, long long v) {
  if (pos < L or pos > R) return;
  if (L == R) {
    bst[a] += v;
    if (v < 0)
      cnt[a]--;
    else
      cnt[a]++;
    return;
  }
  int mid = (L + R) / 2;
  updet(2 * a, L, mid, pos, v);
  updet(2 * a + 1, mid + 1, R, pos, v);
  bst[a] = (bst[2 * a] + bst[2 * a + 1] * bespow[cnt[2 * a]]) % mod;
  cnt[a] = cnt[2 * a] + cnt[2 * a + 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  bespow[0] = 1;
  for (int i = 1; i < nmax; i++) bespow[i] = bespow[i - 1] * bes % mod;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    val = (val + bespow[i] * x) % mod;
  }
  for (int i = 0; i < n; i++) psam = (psam + bespow[i]) % mod;
  vector<int> pos(m + 1);
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    pos[x] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    updet(1, 1, m, pos[i], i);
  }
  if (val == bst[1]) ans++;
  for (int i = n + 1, j = 1; i <= m; i++, j++) {
    updet(1, 1, m, pos[i], i);
    updet(1, 1, m, pos[j], -j);
    if ((val + psam * j) % mod == bst[1]) ans++;
  }
  cout << ans << endl;
}
