#include <bits/stdc++.h>
using namespace std;
int mas[100000];
int main() {
  int n, k;
  int maxx = -1000000001, minn = 1000000001;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
    maxx = max(mas[i], maxx);
    minn = min(mas[i], minn);
  }
  if (k == 2)
    cout << max(mas[0], mas[n - 1]);
  else if (k == 1)
    cout << minn;
  else
    cout << maxx;
  return 0;
}
