#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005], c[100005];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    int min = a[0];
    for (int i = 0; i < n; i++) {
      if (a[i] < min) min = a[i];
      b[i] = min;
    }
    min = a[n - 1];
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] < min) min = a[i];
      c[i] = min;
    }
    sort(a, a + n);
    if (k == 1) {
      printf("%lld\n", a[0]);
      continue;
    }
    if (k == 2) {
      int ans = max(b[0], c[1]);
      for (int i = 1; i < n - 1; i++) {
        if (ans < max(b[i], c[i + 1])) ans = max(b[i], c[i + 1]);
      }
      printf("%d\n", ans);
      continue;
    } else
      printf("%lld\n", a[n - 1]);
  }
  return 0;
}
