#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int B = 10007;
int N, M, pos[maxn], x;
long long g[maxn];
long long val, sum;
struct SegmentTree {
  long long hash[maxn << 2];
  int cnt[maxn << 2];
  void build(int Now, int l, int r) {
    hash[Now] = cnt[Now] = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(Now << 1, l, mid);
    build(Now << 1 | 1, mid + 1, r);
  }
  void pushup(int Now) {
    hash[Now] = hash[Now << 1] * g[cnt[Now << 1 | 1]] + hash[Now << 1 | 1];
    cnt[Now] = cnt[Now << 1] + cnt[Now << 1 | 1];
  }
  void update(int Now, int l, int r, int pos, int val, int num) {
    if (l == r) {
      hash[Now] += num * val;
      cnt[Now] += num;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(Now << 1, l, mid, pos, val, num);
    else
      update(Now << 1 | 1, mid + 1, r, pos, val, num);
    pushup(Now);
  }
} Tree;
int main() {
  while (~scanf("%d%d", &N, &M)) {
    val = sum = 0;
    g[0] = 1;
    for (int i = 1; i <= N; i++) {
      g[i] = g[i - 1] * B, sum += g[i - 1];
    }
    for (int i = 1; i <= N; i++) {
      scanf("%d", &x);
      val = val * B + x;
    }
    for (int i = 1; i <= M; i++) {
      scanf("%d", &x);
      pos[x] = i;
    }
    Tree.build(1, 1, M);
    int ans = 0;
    for (int i = 1; i <= M; i++) {
      Tree.update(1, 1, M, pos[i], i, 1);
      if (i >= N) {
        if (Tree.hash[1] - (sum * (i - N)) == val) ans++;
        Tree.update(1, 1, M, pos[i - N + 1], i - N + 1, -1);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
