#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int A[N];
int mx = -1e9 - 10;
int mn = 1e9 + 10;
int prefixMin[N];
int suffixMin[N];
int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    mn = min(A[i], mn);
    mx = max(A[i], mx);
    prefixMin[i] = mn;
  }
  suffixMin[n] = A[n];
  for (int i = n - 1; i >= 0; i--) {
    suffixMin[i] = min(suffixMin[i + 1], A[i]);
  }
  if (k == 1)
    cout << mn << "\n";
  else if (k == 2) {
    int curAns = -1e9 - 10;
    for (int i = 1; i <= n - 1; i++) {
      curAns = max(curAns, max(prefixMin[i], suffixMin[i + 1]));
    }
    cout << curAns << "\n";
  } else
    cout << mx << "\n";
  return 0;
}
