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