#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5;
int n, k;
int a[MAXN];
int b[MAXN];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (k == 1) {
    int ans = a[0];
    for (int i = 0; i < n; i++) ans = min(ans, a[i]);
    cout << ans << endl;
  } else if (k == 2) {
    b[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      b[i] = min(a[i], b[i + 1]);
    }
    int pref = a[0];
    int ans = max(pref, b[1]);
    for (int i = 1; i < n - 1; i++) {
      pref = min(pref, a[i]);
      ans = max(ans, max(b[i + 1], pref));
    }
    cout << ans << endl;
  } else {
    int ans = a[0];
    for (int i = 0; i < n; i++) {
      ans = max(ans, a[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
