#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
LL mod = 1e9 + 7;
inline int scanInt() {
  int n = 0;
  char ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (int)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
inline LL scanLong() {
  LL n = 0;
  char ch = getchar();
  LL sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (LL)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
int main() {
  LL n = scanLong();
  ;
  LL k = scanLong();
  ;
  LL arr[n];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    arr[i] = scanLong();
  LL maxi = LL(max_element(arr, arr + n) - arr);
  LL mini = LL(min_element(arr, arr + n) - arr);
  if (k == 1)
    printf("%lld ", arr[mini]);
  else if (k == 2) {
    printf("%lld ", max(arr[0], arr[n - 1]));
  } else if (k >= 3)
    printf("%lld ", arr[maxi]);
  printf("\n");
}
