#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
void JTK_1() {
  int t;
  long long n, k;
  cin >> n >> k;
  long long ahm[n];
  long long mx = -1000000009;
  long long mn = 1000000009;
  for (long long i = 0; i < n; i++) {
    cin >> ahm[i];
    mx = max(mx, ahm[i]);
    mn = min(mn, ahm[i]);
  }
  if (k >= 3) {
    cout << mx << endl;
  } else if (k == 2) {
    cout << max(ahm[0], ahm[n - 1]);
  } else {
    cout << mn << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  JTK_1();
  return 0;
}
