#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; // pb_ds
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define EPS (1e-9)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr << #x << ": " << (x) << endl;
void _IO_() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifdef ELARABY
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
// N E S W NW NE SE SW
//int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
//int dc[] = {0, 1, 0, -1, -1, 1, 1, -1};
template<typename T>
void input(vector<T> &v) {
for (T &i: v) {
cin >> i;
}
}
template<typename T>
void output(const vector<T> &v, const int inc = 0) {
for (int i = 0; i < int(v.size()); ++i) {
if (i) cout << ' ';
cout << v[i] + inc;
}
cout << '\n';
}
template<typename T>
void output(const vector<pair<T, T>> &v, const int inc1 = 0, const int inc2 = 0) {
for (int i = 0; i < int(v.size()); ++i) {
cout << v[i].first + inc1 << ' ' << v[i].second + inc2 << '\n';
}
}
//////////////////------PROBLEM SOLUTIONS START FROM HERE------///////////////////
int main() {
_IO_();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(all(a));
int d = 0;
for (int i = 0; i < k; ++i) {
d = max(d + 1, a[i]);
}
cout << d;
return 0;
}
Copy