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