#include #include #include #include int main() { int n{}; int k{}; std::cin >> n >> k; std::vector cost(n); std::copy_n(std::istream_iterator(std::cin), n, cost.begin()); auto result = *std::min_element(cost.begin(), cost.end()); if (1 + 2 * k >= n) { auto begin = std::max(0, n - k - 2); auto end = std::min(n, k + 1); result = *std::min_element(cost.begin() + begin, cost.begin() + end); } std::cout << result << '\n'; return 0; }