#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, min = 10e10, max = -10e10, temp, first, end;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (i == 0) {
      first = temp;
    }
    if (i == n - 1) {
      end = temp;
    }
    if (temp < min) {
      min = temp;
    }
    if (temp > max) {
      max = temp;
    }
  }
  if (k == 1) {
    cout << min;
  } else if (k == 2) {
    cout << (first > end ? first : end);
  } else {
    cout << max;
  }
  cout << "\n";
  return 0;
}
