#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[1000], n, i, m, min = 0, max = 0, a, b;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (i = 1; i <= n; i++) {
    if (ar[i] == 1) min = i;
  }
  for (i = 1; i <= n; i++) {
    if (ar[i] == n) max = i;
  }
  if (min > max) {
    a = n - min;
    b = max - 1;
    if (a > b) {
      cout << n - max << endl;
    } else if (a < b) {
      cout << min - 1 << endl;
    } else if (a == b) {
      cout << n - max << endl;
    }
  } else if (min < max) {
    a = n - max;
    b = min - 1;
    if (a > b) {
      cout << n - min << endl;
    } else if (a < b) {
      cout << max - 1 << endl;
    } else if (a == b) {
      cout << n - min << endl;
    }
  }
}
