#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int M = 1e9 + 100;
long long a[N];
int main() {
  int n, m;
  long long x, y;
  while (~scanf("%d %d", &n, &m)) {
    x = -M;
    y = M;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      x = max(a[i], x);
      y = min(a[i], y);
    }
    if (m == 1)
      printf("%lld\n", y);
    else if (m >= 3)
      printf("%lld\n", x);
    else
      printf("%lld\n", max(a[0], a[n - 1]));
  }
  return 0;
}
