#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int inf = 1e9 + 10;
int main() {
  int n, k;
  int a[maxn];
  scanf("%d %d", &n, &k);
  int ma = -inf;
  int mi = inf;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  if (k == 1)
    printf("%d\n", mi);
  else if (k > 2)
    printf("%d\n", ma);
  else
    printf("%d\n", max(a[0], a[n - 1]));
  return 0;
}
