#include <bits/stdc++.h>
using namespace std;
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
inline int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
const int maxn = 400000;
int a[maxn], b[maxn], la, lb;
int tree_array[maxn];
int kmp[maxn], stat1[maxn];
int ans;
void add(int p, int ad) {
  while (p <= maxn) {
    tree_array[p] += ad;
    p += p & (-p);
  }
}
int que(int a) {
  int temp = 0;
  while (a) {
    temp += tree_array[a];
    a -= a & (-a);
  }
  return temp;
}
void kmp_pre(int *a, int la) {
  kmp[0] = -1;
  kmp[1] = 0;
  for (int i = 0; i < la; i++) {
    add(a[i], 1);
    stat1[i] = que(a[i]);
  }
  memset(tree_array, 0, sizeof(tree_array));
  add(a[1], 1);
  for (int i = 2; i < la; i++) {
    kmp[i] = kmp[i - 1] + 1;
    add(a[i], 1);
    while (que(a[i]) != stat1[kmp[i]]) {
      for (int j = i - kmp[i]; j < i - (kmp[kmp[i] - 1] + 1); j++)
        add(a[j], -1);
      kmp[i] = kmp[kmp[i] - 1] + 1;
    }
  }
}
int main() {
  scanf("%d%d", &la, &lb);
  for (int i = 0; i < la; i++) {
    int temp = 0;
    scanf("%d", &temp);
    temp--;
    a[temp] = i + 1;
  }
  for (int i = 0; i < lb; i++) {
    int temp = 0;
    scanf("%d", &temp);
    temp--;
    b[temp] = i + 1;
  }
  if (la == 1) {
    printf("%d\n", lb);
    return 0;
  }
  kmp_pre(a, la);
  memset(tree_array, 0, sizeof(tree_array));
  int link = 0;
  add(b[0], 1);
  ans = 0;
  for (int i = 1; i < lb + 1; i++) {
    link++;
    if (link == la) ans++;
    if (i == lb) break;
    add(b[i], 1);
    while (link == la || que(b[i]) != stat1[link]) {
      for (int j = i - link; j < i - (kmp[link - 1] + 1); j++) add(b[j], -1);
      link = kmp[link - 1] + 1;
    }
  }
  printf("%d", ans);
  return 0;
}
