#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sub, i, pos;
  cin >> n >> sub;
  int x[n + 2], max_val, min_val;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    if (i == 0)
      max_val = x[i];
    else
      max_val = max(max_val, x[i]);
    if (i == 0)
      min_val = x[i];
    else
      min_val = min(min_val, x[i]);
  }
  if (sub == 1)
    cout << min_val << endl;
  else if (sub == 2)
    cout << max(x[0], x[n - 1]);
  else
    cout << max_val;
}
