#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p1, p2;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int t;
    cin >> t;
    if (t == 1) p1 = i;
    if (t == n) p2 = i;
  }
  if (p1 > p2) swap(p1, p2);
  if (p1 - 1 > n - p2)
    p1 = 1;
  else
    p2 = n;
  int r = p2 - p1;
  cout << r << endl;
}
