#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long x[n + 5];
  long long ma = -12345678965;
  long long mi = 12345678987;
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
    mi = min(mi, x[i]);
    ma = max(ma, x[i]);
  }
  if (m == 1) {
    cout << mi << endl;
  } else if (m == 2) {
    cout << max(x[n - 1], x[0]) << endl;
  } else {
    cout << ma << endl;
  }
  return 0;
}
