#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long temp[n], minv = INT_MAX, maxv = INT_MIN;
  for (long long i = 0; i < n; i++) {
    cin >> temp[i];
    if (temp[i] < minv) minv = temp[i];
    if (temp[i] > maxv) maxv = temp[i];
  }
  if (k == 1)
    cout << minv;
  else if (k == n)
    cout << maxv;
  else {
    if (temp[n - 1] == maxv || temp[0] == maxv || k > 2)
      cout << maxv;
    else {
      cout << max(temp[0], temp[n - 1]);
    }
  }
}
