#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (k == 1) {
    cout << *min_element(arr, arr + n);
  } else if (k == 2) {
    cout << max(arr[0], arr[n - 1]);
  } else {
    cout << *max_element(arr, arr + n);
  }
  return 0;
}
