#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  int a[100861];
  while (~scanf("%d%d", &m, &n)) {
    for (int i = 0; i < m; i++) scanf("%d", &a[i]);
    if (n == 2)
      printf("%d\n", max(a[0], a[m - 1]));
    else {
      sort(a, a + m);
      if (n == 1)
        printf("%d\n", a[0]);
      else
        printf("%d\n", a[m - 1]);
    }
  }
}
