#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<int, int> a;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    if (x == 1)
      a[1] = i;
    else if (x == n)
      a[n] = i;
  }
  if (a[n] < a[1]) {
    if (abs(1 - a[n]) > abs(a[1] - n))
      cout << abs(1 - a[1]);
    else
      cout << abs(n - a[n]);
  } else {
    if (abs(1 - a[1]) > abs(a[n] - n))
      cout << abs(1 - a[n]);
    else
      cout << abs(n - a[1]);
  }
  return 0;
}
