#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& t) {
  for (int i = 0; i < t.size(); i++) in >> t[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& t) {
  for (int i = 0; i < t.size(); i++) out << t[i] << " ";
  return out;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  cin >> v;
  if (k == 1) {
    cout << (*min_element(v.begin(), v.end())) << endl;
    return 0;
  } else if (k > 2) {
    cout << (*max_element(v.begin(), v.end())) << endl;
    return 0;
  } else {
    vector<int> v1(n);
    int mn = 1e9 + 2;
    for (int i = 0; i < n; i++) {
      mn = min(mn, v[i]);
      v1[i] = mn;
    }
    reverse(v.begin(), v.end());
    vector<int> v2(n);
    mn = 1e9 + 2;
    for (int i = 0; i < n; i++) {
      mn = min(mn, v[i]);
      v2[i] = mn;
    }
    reverse(v2.begin(), v2.end());
    int res = -1e9 - 2;
    for (int i = 0; i < n - 1; i++) {
      res = max(res, max(v1[i], v2[i + 1]));
    }
    cout << res << endl;
  }
  return 0;
}
