#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, j, num;
  long long int ans;
  long long int minarray[100010];
  vector<long long int> array;
  vector<long long int>::iterator l;
  cin >> n;
  cin >> k;
  for (i = 0; i < n; i++) {
    cin >> num;
    array.push_back(num);
  }
  if (k == 1) {
    long long int minimum;
    minimum = *min_element(array.begin(), array.end());
    ans = minimum;
  } else if (k == 2) {
    long long int val = array[n - 1];
    minarray[n - 1] = val;
    for (i = n - 2; i >= 0; i--) {
      val = min(val, array[i]);
      minarray[i] = val;
    }
    val = array[0];
    long long int waste;
    ans = max(val, minarray[1]);
    for (i = 1; i < n - 1; i++) {
      val = min(array[i], val);
      waste = max(val, minarray[i + 1]);
      ans = max(ans, waste);
    }
  } else if (k >= 3) {
    long long int maximum;
    maximum = *max_element(array.begin(), array.end());
    ans = maximum;
  }
  cout << ans << endl;
  return 0;
}
