#include <bits/stdc++.h>
using namespace std;
constexpr int fac = 1e9 + 3, mod = 1e9 + 7, N = 2e5 + 1;
int n, m, a[N], b[N], sz[N << 2], hv[N << 2], pw[N];
inline void update(int rt, int l, int r, int tar, int v, int s) {
  if (l == r) {
    hv[rt] += v;
    sz[rt] += s;
    return;
  }
  int mid = (l + r) / 2;
  if (mid < tar)
    update(rt * 2 + 1, mid + 1, r, tar, v, s);
  else
    update(rt * 2, l, mid, tar, v, s);
  hv[rt] = ((long long)hv[rt * 2] * pw[sz[rt * 2 + 1]] + hv[rt * 2 + 1]) % mod;
  sz[rt] = sz[rt * 2] + sz[rt * 2 + 1];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= m; ++i) {
    int x;
    scanf("%d", &x);
    b[x] = i;
  }
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = (long long)pw[i - 1] * fac % mod;
  int hva = a[1];
  for (int i = 2; i <= n; ++i) hva = ((long long)hva * fac + a[i]) % mod;
  int dh = 0;
  for (int i = 0; i < n; i++) dh = (dh + pw[i]) % mod;
  for (int i = 1; i < n; ++i) update(1, 1, m, b[i], i, 1);
  int ans = 0;
  for (int i = n; i <= m; ++i) {
    update(1, 1, m, b[i], i, 1);
    if (hva == hv[1]) ++ans;
    hva = (hva + dh) % mod;
    update(1, 1, m, b[i - n + 1], -i + n - 1, -1);
  }
  printf("%d\n", ans);
}
