#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 7;
const long double pi = 3.14159265359;
const int INF = 1e9 + 7;
const double eps = 1e-9;
const int xi[4] = {+1, 0};
const int yi[4] = {0, +1};
const int xxi[4] = {
    +1,
    0,
    -1,
    0,
};
const int yyi[4] = {
    0,
    -1,
    0,
    +1,
};
int n, a[N];
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int mx = *max_element(a + 1, a + 1 + n);
  int mn = *min_element(a + 1, a + 1 + n);
  int mxpos = 0, mnpos = 0;
  for (int i = 1; i <= n; i++) {
    if (mx == a[i]) {
      mxpos = i;
    }
    if (mn == a[i]) {
      mnpos = i;
    }
  }
  if (mxpos < mnpos) {
    cout << max(n - mxpos, mnpos - 1);
    return 0;
  }
  cout << max(max(n - mnpos, mnpos - 1), mxpos - 1);
}
