#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, i = 0, j = 0, n, m, k = 0, flag = 0, summa = 0;
  string s = "", s1 = "", s2 = "";
  char ch;
  cin >> n >> k;
  long long ms[n], mn = 9999999999, mx = -9999999999;
  for (i = 0; i < n; i++) {
    cin >> ms[i];
    mn = min(mn, ms[i]);
    mx = max(mx, ms[i]);
  }
  if (k == 1)
    cout << mn;
  else if (k > 2)
    cout << mx;
  if (k == 2) {
    long long m1[n - 1], m2[n - 1];
    m1[0] = ms[0];
    m2[n - 2] = ms[n - 1];
    mx = -9999999999;
    for (i = 1; i < n - 1; i++) m1[i] = min(m1[i - 1], ms[i]);
    for (i = n - 3; i >= 0; i--) m2[i] = min(m2[i + 1], ms[i]);
    for (i = 0; i < n - 1; i++) mx = max(mx, max(m1[i], m2[i]));
    cout << mx;
  }
}
