#include <bits/stdc++.h>
using namespace std;
const long long INFLL = 1e18;
const int MAXN = 3e5 + 100;
const long long INF = 1e9;
const long long kek = 998244353;
const long long mod1 = 1e9 + 7;
const long long mod2 = 1e9 + 9;
const long long mod3 = 1e18;
const long long p1 = 1728359;
const long long p2 = 7245962;
vector<long long> hash1(MAXN);
vector<long long> hash2(MAXN);
vector<long long> hash3(MAXN);
vector<long long> hash4(MAXN);
vector<long long> hash5(MAXN);
vector<long long> hash6(MAXN);
vector<long long> pes(MAXN);
vector<long long> pes1(MAXN);
vector<long long> pes2(MAXN);
void make_p(long long mod, vector<long long> &io, long long p) {
  long long f = 1;
  for (int i = 0; i < MAXN; i++) {
    io[i] = f;
    f *= p;
    f %= mod;
  }
}
void make_hash(vector<long long> &a, vector<long long> &hash, long long mod,
               vector<long long> &io) {
  hash[0] = 0;
  for (int i = 1; i <= a.size(); i++) {
    hash[i] = hash[i - 1] + (io[i] * a[i - 1]) % mod;
    hash[i] %= mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  hash1.resize(n);
  hash2.resize(w);
  hash3.resize(n);
  hash4.resize(w);
  hash5.resize(n);
  hash6.resize(w);
  make_p(mod1, pes, p1);
  make_p(mod2, pes1, p2);
  vector<long long> prefp(MAXN);
  vector<long long> prefp1(MAXN);
  prefp[0] = 0;
  prefp1[0] = 0;
  for (int i = 1; i < MAXN; i++) {
    prefp[i] = prefp[i - 1] + pes[i];
  }
  for (int i = 1; i < MAXN; i++) {
    prefp1[i] = prefp1[i - 1] + pes1[i];
  }
  vector<long long> a(n), b(w);
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[i] = x;
  }
  for (int i = 0; i < w; i++) {
    long long x;
    cin >> x;
    b[i] = x;
  }
  make_hash(a, hash1, mod1, pes);
  make_hash(b, hash2, mod1, pes);
  make_hash(a, hash3, mod2, pes1);
  make_hash(b, hash4, mod2, pes1);
  int ans = 0;
  for (int i = 1; i <= n - w + 1; i++) {
    long long q = hash2[w];
    q *= pes[i - 1];
    q %= mod1;
    long long x = hash1[i + w - 1] - hash1[i - 1];
    x %= mod1;
    x += mod1;
    if (x >= mod1) x -= mod1;
    long long t = abs(a[i - 1] - b[0]);
    t %= mod1;
    long long f = (prefp[i + w - 1] - prefp[i - 1]);
    f %= mod1;
    long long l = t * f;
    l %= mod1;
    if (b[0] >= a[i - 1])
      x = x + l;
    else
      x = x - l;
    x %= mod1;
    x += mod1;
    long long g = hash4[w];
    g *= pes1[i - 1];
    g %= mod2;
    long long y = hash3[i + w - 1] - hash3[i - 1];
    y %= mod2;
    y += mod2;
    if (y >= mod2) y -= mod2;
    long long e = abs(a[i - 1] - b[0]);
    e %= mod1;
    long long o = prefp1[i + w - 1] - prefp1[i - 1];
    o %= mod2;
    long long z = o * e;
    z %= mod2;
    if (b[0] >= a[i - 1])
      y += z;
    else
      y -= z;
    y %= mod2;
    y += mod2;
    if (y >= mod2) y -= mod2;
    if (x >= mod1) x -= mod1;
    if (x == q && y == g) {
      ans++;
    }
  }
  cout << ans;
}
