#include <bits/stdc++.h>
const long long int mrx = 1e6 + 5, M = 1e9 + 7, dm = 1e3 + 5;
const long double pi = 3.1415926535897932384626433832795028841971693993751;
long long int mx = -1e18, mn = 1e18;
using namespace std;
long long int n, k, a[mrx];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
    mn = min(mn, a[i]);
  }
  if (k == 1) {
    cout << mn;
  } else if (k == 2) {
    cout << max(a[0], a[n - 1]);
  } else {
    cout << mx;
  }
  return 0;
}
