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