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