#include <bits/stdc++.h>
using namespace std;
struct abc {
  long long int b, c;
};
bool compare(abc x1, abc x2) { return (x1.b < x2.b); }
void swap(long long int *a, long long int *b) {
  long long int temp = *a;
  *a = *b;
  *b = temp;
}
int32_t main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (k == 1)
    cout << *min_element(a, a + n);
  else if (k == 2)
    cout << max(a[0], a[n - 1]);
  else
    cout << *max_element(a, a + n);
}
