#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  std::vector<int> vet(n);
  int p1, pn;
  for (int i = 0; i < n; ++i) {
    cin >> vet[i];
    if (vet[i] == 1) p1 = i;
    if (vet[i] == n) pn = i;
  }
  if (p1 > pn) swap(p1, pn);
  if (p1 == 0 && pn == n - 1) {
    cout << n - 1 << endl;
  } else {
    int d1 = p1;
    int dn = n - 1 - pn;
    cout << pn - p1 + max(d1, dn) << endl;
  }
  return 0;
}
