#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a, best;
  cin >> n >> k >> best;
  for (int i = 1; i < n; i += 1) {
    cin >> a;
    if ((k >= 3 && a > best) || (k == 1 && a < best)) {
      best = a;
    }
  }
  if (k == 2 && a > best) {
    best = a;
  }
  cout << best;
}
