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