#include <bits/stdc++.h>
using namespace std;
const int MIN = 1e3 + 1;
const int MXN = 2e5 + 1;
const int INF = 1e9 + 7;
const long long LINF = 1e18 + 15;
const double EPS = 1e-9;
int n, k, a[MXN], maxi = -INF, mini = INF, pref[MXN], suff[MXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
    mini = min(mini, a[i]);
    pref[i] = mini;
  }
  suff[n + 1] = INF;
  for (int i = n; i >= 1; --i) {
    suff[i] = min(suff[i + 1], a[i]);
  }
  if (k > 2) {
    cout << maxi;
  } else if (k == 1) {
    cout << mini;
  } else {
    maxi = -INF;
    for (int i = 2; i <= n; ++i) {
      maxi = max(maxi, max(suff[i], pref[i - 1]));
    }
    cout << maxi;
  }
  return 0;
}
