#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
  }
  if (k == 1) {
    sort(a.begin(), a.end());
    cout << a[0] << "\n";
  } else {
    if (k == 2) {
      int mx = -INT_MAX, nmx;
      for (int i = 0; i < a.size(); i++) {
        if (a[i] > mx) {
          mx = a[i];
          nmx = i;
        }
      }
      int amn = mx;
      for (int i = 0; i < nmx; i++) {
        if (a[i] < amn) amn = a[i];
      }
      int bmn = mx;
      for (int i = nmx; i < a.size(); i++) {
        if (a[i] < bmn) bmn = a[i];
      }
      if (nmx == a.size() - 1 || nmx == 0) {
        cout << mx << "\n";
        return 0;
      }
      if (amn == mx && bmn != mx)
        cout << max(bmn, max(a[0], a[a.size() - 1])) << "\n";
      if (bmn == mx && amn != mx)
        cout << max(amn, max(a[0], a[a.size() - 1])) << "\n";
      else
        cout << max(amn, max(bmn, max(a[a.size() - 1], a[0]))) << "\n";
    } else {
      sort(a.begin(), a.end());
      cout << a[a.size() - 1] << "\n";
    }
  }
  return 0;
}
