#include <bits/stdc++.h>
using namespace std;
const long long MAXN = +100500;
const long long INF = 4e18;
long long a[MAXN];
int main() {
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (k >= 3) {
    sort(a + 1, a + n + 1);
    cout << a[n];
    return 0;
  }
  if (k == 1) {
    sort(a + 1, a + n + 1);
    cout << a[1];
    return 0;
  }
  multiset<long long> b;
  multiset<long long> c;
  for (int i = 1; i <= n; i++) {
    c.insert(a[i]);
  }
  long long ans = -INF;
  long long pt = 1;
  while (pt < n) {
    b.insert(a[pt]);
    c.erase(c.equal_range(a[pt]).first);
    long long x = max(*c.begin(), *b.begin());
    ans = max(ans, x);
    pt++;
  }
  cout << ans;
}
