#include <bits/stdc++.h>
using namespace std;
int arr[100005], pre[100005], post[100005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int mx, mn;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    if (i == 1)
      mx = mn = arr[i];
    else {
      mx = max(arr[i], mx);
      mn = min(arr[i], mn);
    }
  }
  if (k >= 3) {
    cout << mx << endl;
    return 0;
  } else if (k == 1) {
    cout << mn << endl;
  } else {
    pre[1] = arr[1];
    for (int i = 2; i <= n; i++) pre[i] = min(pre[i - 1], arr[i]);
    post[n] = arr[n];
    for (int i = n - 1; i >= 1; i--) post[i] = min(post[i + 1], arr[i]);
    int ans = max(pre[1], post[2]);
    for (int i = 2; i < n; i++) {
      int MX = max(pre[i], post[i + 1]);
      ans = max(MX, ans);
    }
    cout << ans << endl;
  }
}
