#include <bits/stdc++.h>
using namespace std;
int static fast = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> arr(n, 0);
  for (auto& val : arr) cin >> val;
  if (k == 1) {
    cout << *min_element(arr.begin(), arr.end()) << "\n";
  } else if (k == 2) {
    vector<long long> f(n + 2, INT_MAX);
    vector<long long> b(n + 2, INT_MAX);
    for (int i = 1; i <= n; i++) f[i] = min(f[i - 1], arr[i - 1]);
    for (int i = n; i >= 1; i--) b[i] = min(b[i + 1], arr[i - 1]);
    long long ans = -1e16;
    for (int i = 1; i <= n - 1; i++) ans = max({ans, f[i], b[i + 1]});
    cout << ans << "\n";
  } else {
    cout << *max_element(arr.begin(), arr.end()) << "\n";
  }
  return 0;
}
