#include <bits/stdc++.h>
int main() {
  int num;
  while (scanf("%d", &num) != EOF) {
    int mask[2], masknum = 0;
    int num_map[num];
    for (int i = 0; i < num; i++) {
      scanf("%d", &num_map[i]);
      if (num_map[i] == 1 || num_map[i] == num) {
        mask[masknum] = i + 1;
        masknum++;
      }
    }
    printf("%d\n", mask[1] - mask[0] +
                       ((mask[0] - 1) > (num - mask[1]) ? (mask[0] - 1)
                                                        : (num - mask[1])));
  }
  return 0;
}
