/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[201][12];

void cmemoInit(){
    rep(i, 201){
        rep(j, 12){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> mp(n, 0);
    
    rep(i, m){
        mp[a[i]]++;
    }
    ll ans = n;
    rep(i, n){
        if(mp[i] == 0) ans = min(ans, (ll)i);
    }

    for(ll i = m; i < n; i++){
        mp[a[i]]++;
        mp[a[i - m]]--;
        if(mp[a[i - m]] == 0) ans = min(ans, a[i - m]);
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define mset(a, b) memset(a, b, sizeof(a))
#define Rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define dRep(i, a, b) for(int i = (a); i >= (b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define endl '\n'
#define int ll
#define un unsigned    
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
template<typename _T> inline void prt(_T _d) { cerr<<_d<<' '; }
template <typename _T,typename ...Args> inline void prt(_T _d,Args ..._a) { prt(_d), prt(_a...), putchar('\n'); }
template <typename _T,typename ...Args> inline void cbg(_T _d,Args ..._a) { cerr<<"--at line "<<__LINE__<<"--: "; prt(_d,_a...); }
template<typename _T> inline void rd(_T &_d) { int _f; char _c;_f=_d=0;while(_c=getchar(),!isdigit(_c)) if (_c=='-') _f=1;
while(isdigit(_c)) _d=_d*10+_c-'0',_c=getchar(); 
_d=(_f?-_d:_d);}
template <typename _T,typename ...Args> inline void rd(_T &_d,Args &..._a) { rd(_d);rd(_a...); }

int n,k;

int c(int x) {
	return min(x-1,n)-max(1LL,x-n)+1;
}

signed main() {
	rd(n,k);
	k=abs(k);
	int ans=0;
	Rep(i,k+2,n*2) ans+=c(i)*c(i-k);
	cout<<ans<<endl;
	return 0;
}