#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, temp, max = -1000000000, min = 1000000000, max_ans = -1000000000;
  vector<int> a;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
    if (temp > max) max = temp;
    if (temp < min) min = temp;
    if (min > max_ans) max_ans = min;
  }
  if (k == 1) {
    cout << min;
    return 0;
  }
  if (k >= 3) {
    cout << max;
    return 0;
  }
  if (a[n - 1] > max_ans) max_ans = a[n - 1];
  cout << max_ans;
}
