#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  int a[n];
  int mx = -1e9 - 10;
  int mn = 1e9 + 10;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
    mn = min(mn, a[i]);
  }
  if (k > 2) {
    cout << mx;
  } else if (k == 2) {
    cout << max(a[0], a[n - 1]);
  } else {
    cout << mn;
  }
  return 0;
}
