#include <bits/stdc++.h>
using namespace std;
struct Seg_tree {
  int left, right;
  int size;
  long long hash1, hash2;
} L[200005 << 2];
int n, m;
int a[200005], b[200005], p[200005];
long long fact_2[200005] = {1}, fact_1[200005] = {1};
long long hash_a_1, hash_a_2;
long long sum_1, sum_2;
void bulid(int step, int l, int r) {
  L[step].left = l;
  L[step].right = r;
  L[step].hash1 = L[step].hash2 = 0LL;
  L[step].size = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  bulid(step << 1, l, m);
  bulid(step << 1 | 1, m + 1, r);
}
void push_up(int step) {
  L[step].size = L[step << 1].size + L[step << 1 | 1].size;
  L[step].hash1 = L[step << 1].hash1 * fact_1[L[step << 1 | 1].size] +
                  L[step << 1 | 1].hash1;
  L[step].hash2 = L[step << 1].hash2 * fact_2[L[step << 1 | 1].size] +
                  L[step << 1 | 1].hash2;
}
void update(int step, int pos, int val, int k) {
  if (L[step].left == pos && L[step].right == pos) {
    L[step].size += k;
    L[step].hash1 += k * val;
    L[step].hash2 += k * val;
    return;
  }
  int m = (L[step].left + L[step].right) >> 1;
  if (pos <= m)
    update(step << 1, pos, val, k);
  else
    update(step << 1 | 1, pos, val, k);
  push_up(step);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    hash_a_1 = hash_a_2 = 0;
    sum_1 = sum_2 = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      hash_a_1 = hash_a_1 * 1000003LL + a[i];
      hash_a_2 = hash_a_2 * 999997LL + a[i];
      sum_1 += fact_1[i - 1];
      sum_2 += fact_2[i - 1];
      fact_1[i] = fact_1[i - 1] * 1000003LL;
      fact_2[i] = fact_2[i - 1] * 999997LL;
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d", &b[i]);
      p[b[i]] = i;
    }
    int ans = 0;
    bulid(1, 1, m);
    for (int i = 1; i <= m; i++) {
      update(1, p[i], i, 1);
      if (i > n) update(1, p[i - n], i - n, -1);
      int d = i - n;
      if (d >= 0 && L[1].hash1 == d * sum_1 + hash_a_1 &&
          L[1].hash2 == d * sum_2 + hash_a_2)
        ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
