#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
using namespace std;
const int maxn = 1000 + 10;
int a[maxn * maxn];
int main() {
  int n, k;
  cin >> n >> k;
  int minn = inf, maxx = -inf;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), minn = min(minn, a[i]), maxx = max(maxx, a[i]);
  if (k == 1)
    cout << minn << endl;
  else if (k == 2) {
    cout << max(a[0], a[n - 1]) << endl;
  } else
    cout << maxx << endl;
  return 0;
}
