#include <bits/stdc++.h>
using namespace std;
struct seg {
  int cnt;
  int kkk;
} H[200005 << 2];
int n, m;
int oo, kkk, ans;
int a[200005], b[200005], pos[200005], p[200005];
int mul(int x, int y) { return (long long)x * y % 1000000007; }
int add(int x, int y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
seg merge(seg a, seg b) {
  seg res;
  res.cnt = a.cnt + b.cnt;
  res.kkk = add(mul(b.kkk, p[a.cnt]), a.kkk);
  return res;
}
void up(int node, int bas, int son, int x, int val) {
  if (bas == x && son == x) {
    H[node].cnt += val;
    H[node].kkk += mul(val, mul(p[0], b[x]));
    return;
  }
  if (((bas + son) / 2) >= x)
    up(node << 1, bas, ((bas + son) / 2), x, val);
  else
    up(node << 1 | 1, ((bas + son) / 2) + 1, son, x, val);
  H[node] = merge(H[node << 1], H[node << 1 | 1]);
}
void pre() {
  p[0] = 1;
  for (int i = 1; i <= m; i++) p[i] = mul(p[i - 1], 1000003);
  for (int i = 0; i < n; i++) oo = add(oo, p[i]);
  for (int i = 1; i <= n; i++) kkk = add(kkk, mul(p[i - 1], a[i]));
}
int main() {
  for (int i = 0; i < 200005 << 2; i++) H[i] = {0, 0};
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
  }
  pre();
  for (int i = 1; i <= n; i++) {
    up(1, 1, m, pos[i], 1);
  }
  for (int k = 0; k <= m - n; k++) {
    ans += (H[1].kkk == kkk);
    kkk = add(kkk, oo);
    if (k != m - n) {
      up(1, 1, m, pos[k + 1], -1);
      up(1, 1, m, pos[k + 1 + n], 1);
    }
  }
  printf("%d", ans);
}
