#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  int smallest, largest;
  scanf("%d", &n);
  int v1[n];
  scanf("%d", &k);
  scanf("%d", &v1[0]);
  smallest = largest = v1[0];
  for (int i = 1; i < n; i++) {
    scanf("%d", &v1[i]);
    if (smallest > v1[i]) {
      smallest = v1[i];
    }
    if (largest < v1[i]) {
      largest = v1[i];
    }
  }
  if (k == 1)
    printf("%d", smallest);
  else if (k == 2) {
    if (v1[0] > v1[n - 1])
      printf("%d", v1[0]);
    else
      printf("%d", v1[n - 1]);
  } else {
    printf("%d", largest);
  }
  return 0;
}
