#include <bits/stdc++.h>
using namespace std;
const int SZ = 200010;
const int INF = 1000000010;
int read() {
  int n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a >= '0' && a <= '9') {
    n = n * 10 + a - '0';
    a = getchar();
  }
  if (flag) n = -n;
  return n;
}
int num[SZ];
int main() {
  int n = read();
  int pos1, pos2;
  for (int i = 1; i <= n; i++) {
    num[i] = read();
    if (num[i] == 1) pos1 = i;
    if (num[i] == n) pos2 = i;
  }
  if (n == 1) {
    printf("0");
    return 0;
  }
  if (n == 2) {
    printf("1");
    return 0;
  }
  if (((pos1 == 1 && pos2 == n) || (pos1 == n || pos2 == 1))) {
    printf("%d", n - 1);
    return 0;
  }
  printf("%d\n", max(max(abs(n - pos1), abs(1 - pos1)),
                     max(abs(n - pos2), abs(1 - pos2))));
  return 0;
}
