#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  ios_base::sync_with_stdio(0);
  int mx = -INF, mn = INF;
  int n, k;
  cin >> n >> k;
  int begin, end;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (i == 0) begin = x;
    if (i == n - 1) end = x;
    mx = max(mx, x);
    mn = min(mn, x);
  }
  if (k >= 3) {
    cout << mx << endl;
  } else if (k == 2) {
    cout << max(begin, end) << endl;
  } else if (k == 1) {
    cout << mn << endl;
  }
  return 0;
}
