#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int sz[maxn << 2];
long long Hash[maxn << 2][2], sum[2], f[2], h[maxn][2];
int bb[] = {1000009, 999997};
int ld[maxn << 2], rd[maxn << 2];
int a[maxn], b[maxn];
void build(int l, int r, int rt) {
  ld[rt] = l, rd[rt] = r;
  Hash[rt][0] = Hash[rt][1] = 0;
  sz[rt] = 0;
  if (l == r) {
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void PushUp(int rt) {
  sz[rt] = sz[rt << 1] + sz[rt << 1 | 1];
  Hash[rt][0] = Hash[rt << 1][0] * h[sz[rt << 1 | 1]][0] + Hash[rt << 1 | 1][0];
  Hash[rt][1] = Hash[rt << 1][1] * h[sz[rt << 1 | 1]][1] + Hash[rt << 1 | 1][1];
}
void update(int l, int r, int rt, int pos, int val, int k) {
  if (l == pos && r == pos) {
    sz[rt] += k;
    Hash[rt][0] += k * val;
    Hash[rt][1] += k * val;
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m)
    update(l, m, rt << 1, pos, val, k);
  else
    update(m + 1, r, rt << 1 | 1, pos, val, k);
  PushUp(rt);
}
int main() {
  h[0][0] = h[0][1] = 1;
  int n, m;
  cin >> n >> m;
  for (int i = (1); i < (n + 1); i++) {
    cin >> a[i];
    for (int k = 0; k < (2); k++) {
      sum[k] = sum[k] * bb[k] + a[i];
      h[i][k] = h[i - 1][k] * bb[k];
      f[k] += h[i - 1][k];
    }
  }
  for (int i = (1); i < (m + 1); i++) {
    int t;
    cin >> t;
    b[t] = i;
  }
  long long ans = 0;
  build(1, m, 1);
  for (int i = (1); i < (m + 1); i++) {
    update(1, m, 1, b[i], i, 1);
    if (i > n) update(1, m, 1, b[i - n], i - n, -1);
    int d = i - n;
    if (d >= 0) {
      if (Hash[1][0] == d * f[0] + sum[0] && Hash[1][1] == d * f[1] + sum[1])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
