#include <bits/stdc++.h>
const int BIG = 1e5 + 55;
const int BIGG = 1e9 + 55;
const long long BIGGE = 1e12 + 55;
const double SML = (1e-7);
using namespace std;
int n, k, a[100009], b[100009];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
  sort(a, a + n);
  if (k == 1)
    cout << a[0];
  else if (k == 2)
    cout << max(b[0], b[n - 1]);
  else
    cout << a[n - 1];
  return 0;
}
