#include <bits/stdc++.h>
int main() {
  int num, parts;
  std::cin >> num >> parts;
  int data[num];
  for (int i = 0; i < num; ++i) {
    std::cin >> data[i];
  }
  if (parts == 1) {
    int* i1;
    i1 = std::min_element(data, data + num);
    std::cout << *i1;
  } else if (parts == 2) {
    std::cout << std::max(data[0], data[num - 1]);
  } else {
    int* i1;
    i1 = std::max_element(data, data + num);
    std::cout << *i1;
  }
}
