#include <bits/stdc++.h>
using namespace std;
void fun();
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n];
  long long int maxi, mini;
  maxi = LONG_MIN;
  mini = LONG_MAX;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    maxi = max(maxi, arr[i]);
    mini = min(mini, arr[i]);
  }
  if (k == 1) {
    cout << mini << endl;
  } else if (k == 2) {
    long long int num = arr[0];
    long long int a = LONG_MAX;
    for (int i = 1; i < n; i++) {
      a = min(a, arr[i]);
    }
    long long int b = max(a, num);
    long long int tum = arr[n - 1];
    long long int c = LONG_MAX;
    for (long long int i = n - 2; i >= 0; i--) {
      c = min(c, arr[i]);
    }
    long long int d = max(tum, c);
    cout << max(d, b) << endl;
  } else {
    cout << maxi << endl;
  }
  return 0;
}
