#include <bits/stdc++.h>
using namespace std;
long long int C, MOD;
struct BIT {
  long long int bit[200005];
  void init() { memset(bit, 0, sizeof(bit)); }
  void add(int k, long long int x) {
    while (k < 200005) {
      bit[k] += x;
      if (bit[k] >= MOD) bit[k] -= MOD;
      k += k & -k;
    }
  }
  long long int get(int k) {
    long long int ret = 0;
    while (k > 0) {
      ret += bit[k];
      if (ret >= MOD) ret -= MOD;
      k -= k & -k;
    }
    return ret;
  }
  long long int get(int s, int t) { return (get(t) - get(s - 1) + MOD) % MOD; }
};
BIT b1, b2;
int A[200005], B[200005];
long long int rt[200005];
bool use[200005];
int n, m;
void solve(int t) {
  if (t == 0)
    C = 89793, MOD = 1000000007;
  else
    C = 981793, MOD = 1000000009;
  long long int ha = 0;
  for (int i = n - 1; i >= 0; i--) {
    ha *= C;
    ha += (long long int)A[i];
    ha %= MOD;
  }
  rt[0] = 1;
  for (int i = 1; i <= m; i++) rt[i] = rt[i - 1] * C % MOD;
  long long int hb = 0;
  b1.init();
  b2.init();
  for (int i = m - 1; i >= 0; i--) {
    hb += b1.get(B[i] + 1, m + 1);
    hb += b2.get(B[i] + 1) * rt[i] % MOD;
    hb %= MOD;
    b1.add(B[i] + 1, rt[i]);
    b2.add(B[i] + 1, 1);
    if (i + n <= m) {
      if (ha * rt[i] % MOD != hb) use[i] = false;
      b1.add(B[i + n - 1] + 1, (MOD - rt[i + n - 1]) % MOD);
      b2.add(B[i + n - 1] + 1, MOD - 1);
      hb -= b1.get(B[i + n - 1] + 1, m + 1);
      if (hb < 0) hb += MOD;
      hb -= b2.get(B[i + n - 1] + 1) * rt[i + n - 1] % MOD;
      if (hb < 0) hb += MOD;
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    A[p] = i;
  }
  for (int i = 0; i < m; i++) {
    int p;
    scanf("%d", &p);
    p--;
    B[p] = i;
  }
  for (int i = 0; i + n <= m; i++) use[i] = true;
  solve(0);
  solve(1);
  int ret = 0;
  for (int i = 0; i + n <= m; i++) ret += use[i];
  printf("%d\n", ret);
  return 0;
}
