#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i,n) for (int i = 0; i < (int)(n); i++)

using namespace std;

typedef unsigned long long ull;

int main()
{
  ull x,y;
  cin>>x>>y;
  
  if(x==y){
    cout<<x;
  }else{
    switch(x+y){
      case 1:
        cout<<2;
        break;
      case 2:
        cout<<1;
        break;
      case 3:
        cout<<0;
        break;
    }
  }
  
  return 0;
}
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep1(i, n) for (int i = n; i >= 1; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define eb emplace_back
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef long long int ll;
typedef pair<int, int> P;
// typedef modint1000000007 mint;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

void speedUpIO() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
}
/*--------------------------------------------------*/

void solve() {
    int n, m;
    cin >> n >> m;
    V<int> a(n);
    rep(i, n) cin >> a[i];
    V<int> cnt(n + 1);
    rep(i, m) cnt[a[i]]++;
    int ans = n;
    rep(i, n) {
        if (cnt[i] == 0) {
            ans = i;
            break;
        }
    }
    for (int i = 1; i <= n - m; i++) {
        int l = i - 1;
        int r = i + m - 1;
        // if (cnt[a[l]] == 0) chmin(ans, a[l]);
        cnt[a[l]]--;
        cnt[a[r]]++;
        if (cnt[a[l]] == 0) chmin(ans, a[l]);
    }
    rep(i, n) {
        if (cnt[i] == 0) {
            chmin(ans, i);
            break;
        }
    }
    cout << ans << "\n";
}

int main() {
    speedUpIO();
    solve();
    return 0;
}
