#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n], t1 = -1, tn = -1;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      t1 = i + 1;
    } else if (a[i] == n) {
      tn = i + 1;
    }
  }
  long long maxd = -1, t2 = -1, tn2 = -1;
  if (t1 < tn) {
    t2 = 1;
    tn2 = n;
    maxd = max({abs(t2 - tn), abs(tn2 - t1)});
  } else if (t1 > t2) {
    tn2 = 1;
    t2 = n;
    maxd = max({abs(t2 - tn), abs(tn2 - t1)});
  }
  cout << maxd << endl;
  return 0;
}
