#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[101], n, l, r;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
      if (arr[i] == 1) l = i + 1;
      if (arr[i] == n) r = i + 1;
    }
    if (l > r)
      printf("%d\n", l - r + max(n - l, r - 1));
    else
      printf("%d\n", r - l + max(n - r, l - 1));
  }
  return 0;
}
