#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const long long M = 9999991;
const int mod = 1e9 + 7;
long long tem[N], sum, s;
int num[N], pos[N];
struct node {
  int l;
  int r;
  int son;
  long long sum;
} tree[N << 2];
void init() {
  tem[0] = 1;
  s = sum = 0;
}
void make_tree(int l, int r, int id) {
  int ls = id << 1, rs = ls + 1, mid = (l + r) >> 1;
  tree[id].l = l;
  tree[id].r = r;
  tree[id].sum = tree[id].son = 0;
  if (l == r) return;
  make_tree(l, mid, ls);
  make_tree(mid + 1, r, rs);
}
void update(int s, int number, int x, int id) {
  if (tree[id].l == tree[id].r) {
    tree[id].son += x;
    tree[id].sum += number;
    return;
  }
  int ls = id << 1, rs = ls + 1, mid = (tree[id].l + tree[id].r) >> 1;
  if (s <= mid)
    update(s, number, x, ls);
  else
    update(s, number, x, rs);
  tree[id].son = tree[ls].son + tree[rs].son;
  tree[id].sum =
      ((tree[ls].sum * tem[tree[rs].son]) % mod + tree[rs].sum) % mod;
}
int main() {
  int n, m;
  int in;
  while (scanf("%d %d", &n, &m) != EOF) {
    init();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &in);
      tem[i] = (M * tem[i - 1]) % mod;
      sum = (sum * M + in) % mod;
      s = (s + tem[i - 1]) % mod;
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d", &num[i]);
      pos[num[i]] = i;
    }
    make_tree(1, m, 1);
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      update(pos[i], i, 1, 1);
      if (i > n) update(pos[i - n], -(i - n), -1, 1);
      if (i >= n) {
        if ((tree[1].sum - ((i - n) * s) % mod + mod) % mod == sum) ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
