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