#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  if (k == 1)
    cout << b[0] << endl;
  else if (k == 2) {
    if (a[0] > a[n - 1])
      cout << a[0] << endl;
    else
      cout << a[n - 1] << endl;
  } else
    cout << b[n - 1] << endl;
}
