#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &x) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-' && c != -1)
    ;
  if (c == -1) return;
  if (c == '-') sg = 1, c = getchar();
  for (x = 0; c >= '0' && c <= '9';
       x = (x << 1) + (x << 3) + c - '0', c = getchar())
    ;
  if (sg) x = -x;
}
template <class T>
void print(T x) {
  if (x < 0) return putchar('-'), print(-x);
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
template <class U, class V>
inline void gn(U &u, V &v) {
  gn(u);
  gn(v);
}
template <class U, class V, class W>
inline void gn(U &u, V &v, W &w) {
  gn(u);
  gn(v, w);
}
template <class T>
void println(T &x) {
  print(x);
  putchar('\n');
}
template <class T>
void printsp(T &x) {
  print(x);
  putchar(' ');
}
template <class U, class V>
inline void print(U &u, V &v) {
  printsp(u);
  println(v);
}
template <class U, class V, class W>
inline void print(U &u, V &v, W &w) {
  printsp(u);
  print(v, w);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; a = (long long)a * a % m, b >>= 1)
    if (b & 1) ans = (long long)ans * a % m;
  return ans;
}
int f[220202], id[220202];
int H[220202 * 4], cnt[220202 * 4];
void push_up(int u) {
  cnt[u] = cnt[u << 1] + cnt[u << 1 | 1];
  H[u] =
      ((long long)H[u << 1] * f[cnt[u << 1 | 1]] % 1000000007 + H[u << 1 | 1]) %
      1000000007;
}
void update(int u, int L, int R, int l, int r, int v, char flag = 'a') {
  if (l >= R || r <= L) return;
  if (L + 1 == R) {
    if (flag == 'd')
      cnt[u] = 0, H[u] = 0;
    else
      cnt[u] = 1, H[u] = v;
    return;
  }
  update(u << 1, L, (L + R) >> 1, l, r, v, flag);
  update(u << 1 | 1, (L + R) >> 1, R, l, r, v, flag);
  push_up(u);
}
int main() {
  int n, m;
  gn(n, m);
  f[0] = 1;
  int tmp = 0;
  int ins = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    gn(x);
    tmp = ((long long)tmp * 11 % 1000000007 + x) % 1000000007;
    f[i] = (long long)f[i - 1] * 11 % 1000000007;
    ins = (ins + f[i - 1]) % 1000000007;
  }
  for (int i = 0; i < m; i++) {
    int x;
    gn(x);
    id[x] = i;
  }
  for (int i = 1; i < n; i++) update(1, 0, m, id[i], id[i] + 1, i);
  int ans = 0;
  for (int i = n; i <= m; i++) {
    update(1, 0, m, id[i], id[i] + 1, i);
    if (tmp == H[1]) ans++;
    tmp = (tmp + ins) % 1000000007;
    update(1, 0, m, id[i - n + 1], id[i - n + 1] + 1, i - n + 1, 'd');
  }
  println(ans);
  return 0;
}
