#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a == 1) {
      b = i;
    }
    if (a == n) {
      c = i;
    }
  }
  if (b > c) {
    a = c;
    c = b;
    b = a;
  }
  if (b - 1 > n - c) {
    cout << c - 1 << endl;
  } else {
    cout << n - b << endl;
  }
  return 0;
}
