#include <bits/stdc++.h>
const int maxn = 800001;
int a[maxn], n, m, i, rank, x, ans, sizes[maxn];
unsigned long long v[maxn], sum, tree[maxn];
using namespace std;
void insert(int k, int l, int r, int p, int x, int rank) {
  int mid = (l + r) / 2;
  if (l == r) {
    sizes[k] = x;
    if (x)
      tree[k] = rank;
    else
      tree[k] = 0;
    return;
  }
  if (p <= mid)
    insert(k * 2, l, mid, p, x, rank);
  else
    insert(k * 2 + 1, mid + 1, r, p, x, rank);
  sizes[k] = sizes[k * 2] + sizes[k * 2 + 1];
  tree[k] = tree[k * 2 + 1] + tree[k * 2] * v[sizes[k * 2 + 1]];
}
int main() {
  scanf("%d%d", &n, &m);
  unsigned long long hash = 0;
  v[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[x] = i;
    v[i] = v[i - 1] * 10000007;
    sum += v[i - 1];
    hash = hash * 10000007 + x;
  }
  memset(tree, 0, sizeof(tree));
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) insert(1, 1, m, a[i], 1, i);
  if (tree[1] == hash) ans++;
  for (int i = n + 1; i <= m; i++) {
    insert(1, 1, m, a[i - n], 0, 0);
    insert(1, 1, m, a[i], 1, i);
    if (tree[1] == hash + sum * (i - n)) ans++;
  }
  cout << ans << endl;
  fclose(stdin);
  return 0;
}
