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