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