#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
long long arr[maxn], n, k, mnv = 1000000000, mxv = -1000000000;
int main() {
  scanf("%lld %lld", &n, &k);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    mxv = max(mxv, arr[i]);
    mnv = min(mnv, arr[i]);
  }
  if (k == 1) {
    printf("%lld\n", mnv);
  } else if (k == 2) {
    long long f = arr[0], b = arr[1];
    for (long long i = 2; i < n; i++) b = min(b, arr[i]);
    long long ansa = max(f, b);
    f = arr[n - 1], b = arr[n - 2];
    for (long long i = n - 3; i >= 0; i--) b = min(b, arr[i]);
    long long ansb = max(f, b);
    printf("%lld\n", max(ansa, ansb));
  } else {
    printf("%lld\n", mxv);
  }
  return 0;
}
