#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int i;
  long long int a[n + 1];
  long long int max = -1000000001;
  long long int min = 1000000001;
  long long int m1[n + 1];
  long long int m2[n + 1];
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] > max) max = a[i];
    if (a[i] < min) min = a[i];
  }
  m1[1] = a[1];
  m2[1] = a[n];
  for (i = 2; i <= n; i++) {
    if (a[i] < m1[i - 1])
      m1[i] = a[i];
    else
      m1[i] = m1[i - 1];
  }
  for (i = 2; i <= n; i++) {
    if (a[n + 1 - i] < m2[i - 1])
      m2[i] = a[n + 1 - i];
    else
      m2[i] = m2[i - 1];
  }
  if (k >= 3) {
    printf("%lld\n", max);
    return 0;
  } else if (k == 2) {
    long long int ans = -1000000001;
    for (i = 1; i <= n - 1; i++) {
      int temp;
      if (m1[i] > m2[n - i])
        temp = m1[i];
      else
        temp = m2[n - i];
      if (temp > ans) ans = temp;
    }
    printf("%lld\n", ans);
    return 0;
  } else
    printf("%lld\n", min);
  return 0;
}
