#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, k, i, j, p = 1e9, q = -1e9, s = -1e9;
  cin >> x >> k;
  int n[x];
  for (i = 0; i < x; i++) {
    cin >> n[i];
    if (n[i] > s) s = n[i];
    if (n[i] < p) p = n[i];
  }
  if (k == 1)
    cout << p << endl;
  else if (k == 2) {
    q = max(n[0], n[x - 1]);
    cout << q << endl;
  } else
    cout << s << endl;
}
