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