#include <bits/stdc++.h>
using namespace std;
long long a[200000];
int main() {
  long long i, j, k, n, m, t1, t2, t3, t4, t5;
  cin >> n >> m;
  t4 = t5 = -1000000009;
  t1 = -1000000009;
  t2 = 1000000009;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    t1 = max(t1, a[i]);
    t2 = min(t2, a[i]);
  }
  if (m == 1)
    cout << t2;
  else if (m == 2)
    cout << max(a[0], a[n - 1]);
  else
    cout << t1;
  return 0;
}
