#include <bits/stdc++.h>
using namespace std;
long long i, j, n, t, m, x = 1e9, z, k, a[100009], b[100009], ans = -1e9, f,
                         sum, sz;
int main() {
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ans = max(ans, a[i]);
    x = min(x, a[i]);
  }
  if (k > 2)
    cout << ans << endl;
  else if (k == 2) {
    ans = -1e9;
    ans = max(ans, a[0]);
    ans = max(ans, a[n - 1]);
    cout << ans << endl;
  } else
    cout << x << endl;
  return 0;
}
