#include <bits/stdc++.h>
using namespace std;
unsigned long long t[524288], h[200005] = {1};
int s[524288], a[200005];
int edit(int p, int v, int x, int y, int i) {
  if (x + 1 == y) return s[i] = !!(t[i] = v);
  int m = (x + y) / 2, j = i * 2 + 1, k = j + 1;
  if (p >= m)
    edit(p, v, m, y, k);
  else
    edit(p, v, x, m, j);
  t[i] = t[k] + t[j] * h[s[k]];
  return s[i] = s[j] + s[k];
}
int main() {
  int n, m, x, ans = 0;
  unsigned long long tag = 0, sum = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    tag = tag * 9875321 + x;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    a[x - 1] = i;
    h[i + 1] = h[i] * 9875321;
  }
  for (int i = 0; i < n; i++) {
    sum += h[i];
    edit(a[i], i + 1, 0, m, 0);
  }
  if (tag == t[0]) ans++;
  for (int i = n; i < m; i++) {
    edit(a[i], i + 1, 0, m, 0);
    edit(a[i - n], 0, 0, m, 0);
    if (tag + sum * (i - n + 1) == t[0]) ans++;
  }
  printf("%d\n", ans);
}
