#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int arrsz, sn;
int mx;
int arr[N];
void init();
void process();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  process();
  cout.flush();
  return 0;
}
void init() {
  mx = -(1 << 30);
  cin >> arrsz >> sn;
  for (int i = 0; i < arrsz; i++) {
    cin >> arr[i];
    if (arr[i] > mx) mx = arr[i];
  }
}
void process() {
  if (sn > 2)
    cout << mx << '\n';
  else if (sn == 2) {
    int mx = -(1 << 30);
    int mnh = (1 << 30), mnr = (1 << 30);
    for (int i = 0; i < arrsz; i++) {
      if (arr[i] < mnh) mnh = arr[i];
      if (arr[arrsz - 1 - i] < mnr) mnr = arr[arrsz - 1 - i];
      if (mnh > mx) mx = mnh;
      if (mnr > mx) mx = mnr;
    }
    cout << mx << '\n';
  } else {
    int mn = (1 << 30);
    for (int i = 0; i < arrsz; i++)
      if (arr[i] < mn) mn = arr[i];
    cout << mn << '\n';
  }
}
