#include <bits/stdc++.h>
using namespace std;
int a[100007];
int main() {
  int n, k;
  int maxm, minm;
  while (scanf("%d%d", &n, &k) != EOF) {
    maxm = -0x3f3f3f3f;
    minm = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      maxm = max(a[i], maxm);
      minm = min(a[i], minm);
    }
    if (k == 1)
      printf("%d\n", minm);
    else if (k == 2)
      printf("%d\n", max(a[0], a[n - 1]));
    else {
      printf("%d\n", maxm);
    }
  }
  return 0;
}
