#include <bits/stdc++.h>
using namespace std;
int n, k;
long long mx = -(1e15);
long long mn = 1e15;
int main() {
  cin >> n >> k;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mx = max(mx, v[i]);
    mn = min(mn, v[i]);
  }
  if (k == 1) {
    cout << mn;
    return 0;
  }
  if (k >= 3) {
    cout << mx;
    return 0;
  }
  mx = -(1e15);
  mn = 1e15;
  for (int i = 0; i < n; i++) {
    mn = min(mn, v[i]);
    mx = max(mx, mn);
  }
  mn = 1e15;
  for (int i = n - 1; i >= 0; i--) {
    mn = min(mn, v[i]);
    mx = max(mx, mn);
  }
  cout << mx;
  return 0;
}
