#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, m, l;
  cin >> n >> k;
  long long a[n];
  cin >> a[0];
  m = a[0];
  l = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    m = max(a[i], m);
    l = min(l, a[i]);
  }
  cout << m * (k > 2) + l * (k == 1) + max(a[0], a[n - 1]) * (k == 2);
  return 0;
}
