#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T1, class T2>
inline void gn(T1 &x1, T2 &x2) {
  gn(x1), gn(x2);
}
template <class T1, class T2, class T3>
inline void gn(T1 &x1, T2 &x2, T3 &x3) {
  gn(x1), gn(x2), gn(x3);
}
template <class T1, class T2, class T3, class T4>
inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
  gn(x1), gn(x2), gn(x3), gn(x4);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T1, class T2>
inline void print(T1 x1, T2 x2) {
  printsp(x1), println(x2);
}
template <class T1, class T2, class T3>
inline void print(T1 x1, T2 x2, T3 x3) {
  printsp(x1), printsp(x2), println(x3);
}
template <class T1, class T2, class T3, class T4>
inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {
  printsp(x1), printsp(x2), printsp(x3), println(x4);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int p[200010], pos[200010];
int tmp, add;
int cnt[777777], val[777777];
void push_up(int u) {
  cnt[u] = cnt[(u << 1)] + cnt[((u << 1) | 1)];
  val[u] = (1LL * val[(u << 1)] * p[cnt[((u << 1) | 1)]] % 1000000007 +
            val[((u << 1) | 1)]) %
           1000000007;
}
void update(int u, int st, int ed, int id, int v, int ok = 0) {
  if (id < st or id >= ed) return;
  if (st + 1 == ed) {
    if (ok)
      val[u] = cnt[u] = 0;
    else
      val[u] = v, cnt[u] = 1;
    return;
  }
  update((u << 1), st, (st + ed >> 1), id, v, ok);
  update(((u << 1) | 1), (st + ed >> 1), ed, id, v, ok);
  push_up(u);
}
int main() {
  int n, m, first;
  gn(n, m);
  for (int i = p[0] = 1; i <= n; i++) {
    gn(first);
    tmp = (7LL * tmp % 1000000007 + first) % 1000000007;
    p[i] = 7LL * p[i - 1] % 1000000007;
    add = (add + p[i - 1]) % 1000000007;
  }
  for (int i = 0; i < m; i++) {
    gn(first);
    pos[first] = i;
  }
  for (int i = 1; i < n; i++) update(1, 0, m, pos[i], i);
  int ans = 0;
  for (int i = n; i <= m; i++) {
    update(1, 0, m, pos[i], i);
    if (val[1] == tmp) ans++;
    tmp = (tmp + add) % 1000000007;
    update(1, 0, m, pos[i - n + 1], i - n + 1, 1);
  }
  println(ans);
}
