#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ans;
  cin >> n >> k >> ans;
  while (--n) {
    int a;
    cin >> a;
    if (k == 1)
      ans = min(ans, a);
    else if (k > 2)
      ans = max(ans, a);
    else if (n == 1)
      ans = max(ans, a);
  }
  cout << ans;
  return 0;
}
