#include <bits/stdc++.h>
using namespace std;
const int c = 1331;
const int p = 999999997;
const int maxN = 200005;
struct Node {
  int s, h, fa, lc, rc, v;
} t[maxN];
int mi[maxN], a[maxN], b[maxN];
int n, m, k, root, sa[maxN];
int mul(long long x, long long y) {
  x *= y;
  if (x >= p) x %= p;
  return x;
}
void add(int &x, int y) {
  x += y;
  if (x >= p) x -= p;
}
void Init() {
  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);
    t[b[i]].lc = root;
    t[root].fa = b[i];
    root = b[i];
  }
  mi[0] = k = 1;
  for (int i = 1; i <= n - 1; ++i) {
    mi[i] = mul(mi[i - 1], c);
    add(k, mi[i]);
  }
}
void ud(int x) {
  int l = t[x].lc, r = t[x].rc;
  t[x].s = t[l].s + t[r].s + bool(t[x].v);
  t[x].h = 0;
  add(t[x].h, mul(t[r].h, mi[t[x].s - t[r].s]));
  add(t[x].h, mul(t[x].v, mi[t[l].s]));
  add(t[x].h, t[l].h);
}
void Zig(int x) {
  int y = t[x].fa;
  if (t[t[y].fa].lc == y)
    t[t[y].fa].lc = x;
  else
    t[t[y].fa].rc = x;
  t[x].fa = t[y].fa;
  t[y].lc = t[x].rc;
  t[t[x].rc].fa = y;
  t[x].rc = y;
  t[y].fa = x;
  ud(y);
}
void Zag(int x) {
  int y = t[x].fa;
  if (t[t[y].fa].lc == y)
    t[t[y].fa].lc = x;
  else
    t[t[y].fa].rc = x;
  t[x].fa = t[y].fa;
  t[y].rc = t[x].lc;
  t[t[x].lc].fa = y;
  t[x].lc = y;
  t[y].fa = x;
  ud(y);
}
void splay(int x) {
  int y, z;
  while (t[x].fa) {
    y = t[x].fa;
    z = t[y].fa;
    if (!z)
      if (x == t[y].lc)
        Zig(x);
      else
        Zag(x);
    else if (y == t[z].lc)
      if (x == t[y].lc)
        Zig(y), Zig(x);
      else
        Zag(x), Zig(x);
    else if (x == t[y].rc)
      Zag(y), Zag(x);
    else
      Zig(x), Zag(x);
  }
  ud(root = x);
}
void make(int x, int d) {
  splay(x);
  t[x].v = d;
  ud(x);
}
void Work() {
  int mb = 0, ans = 0;
  for (int i = 1; i <= n; ++i) add(mb, mul(a[i], mi[i - 1]));
  for (int i = 1; i <= n; ++i) make(i, i);
  for (int i = n; i <= m; ++i) {
    if (t[root].h == mb) ++ans;
    make(i - n + 1, 0);
    make(i + 1, i + 1);
    add(mb, k);
  }
  printf("%d\n", ans);
}
int main() {
  Init();
  Work();
  return 0;
}
