#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int main() {
  int n, m;
  int a, b, x, y, mins = inf, maxs = -inf;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (i == 0) x = a;
    if (i == n - 1) y = a;
    mins = min(mins, a);
    maxs = max(maxs, a);
  }
  if (m == 1)
    printf("%d\n", mins);
  else if (m == 2)
    printf("%d\n", max(x, y));
  else
    printf("%d\n", maxs);
}
