#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double eps = 10e-7;
const int sz = 8;
int main() {
  int n, k, minim = 0, maxim = 0;
  static int a[100000];
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > a[maxim]) maxim = i;
    if (a[i] < a[minim]) minim = i;
  }
  if (k == 1)
    printf("%d", a[minim]);
  else if (k > 2)
    printf("%d", a[maxim]);
  else {
    printf("%d", max(a[0], a[n - 1]));
  }
  return 0;
}
