#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void input(T &x) {
  register char c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1e5 + 5;
int a[N];
const int INF = 1e9 + 9;
int dp[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (k == 1) {
    int ans = INF;
    for (int i = 0; i < n; i++) ans = min(ans, a[i]);
    cout << ans << endl;
  } else if (k == 2) {
    int pre = INF;
    for (int i = 0; i < n; i++) {
      dp[i] = min(a[i], pre);
      pre = dp[i];
    }
    pre = INF;
    int ans = -INF;
    for (int i = n - 1; i > 0; i--) {
      pre = min(a[i], pre);
      ans = max(ans, max(dp[i - 1], pre));
    }
    cout << ans << endl;
  } else {
    int ans = -INF;
    for (int i = 0; i < n; i++) ans = max(ans, a[i]);
    cout << ans << endl;
  }
  return 0;
}
