#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int INF = 1e9 + 7;
const long double EPS = 1e-9;
const long double PI = 3.141592653589793;
inline void start(void) {
  cout << fixed << setprecision(16);
  srand(INF);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
inline void bye(void) { exit(0); }
int main(void) {
  start();
  int n, k;
  cin >> n >> k;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  auto minn = min_element(arr.begin(), arr.end());
  auto maxx = max_element(arr.begin(), arr.end());
  if (k == 1) {
    cout << *minn;
  } else if (k >= 3) {
    cout << *maxx;
  } else if (k == 2) {
    cout << max(arr.back(), arr.front());
  }
  cout << "\n";
  bye();
}
