#include <iostream>
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int k, n;cin >> n>> k;
vector<int>t(n); ll d = 0;
for (int i = 0; i < n; i++)
cin >> t[i];
sort(t.begin(), t.end());
d = t[0];
for (int i = 1; i < k; i++) {
if (d < t[i]) d = t[i];
else d++;
}
cout << d;
return 0;
}