#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int m1, m2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) m1 = i;
    if (a[i] == n) m2 = i;
  }
  int b[3], c[3];
  b[0] = m1;
  c[0] = m2;
  b[1] = m1, b[2] = m1;
  if (n != a[0]) b[1] = 0;
  if (a[n - 1] != n) b[2] = n - 1;
  c[1] = m2, c[2] = m2;
  if (1 != a[0]) c[1] = 0;
  if (1 != a[n - 1]) c[2] = n - 1;
  int ma = 0;
  for (int i = 0; i < 3; i++) {
    ma = max(ma, abs(b[i] - m2));
  }
  for (int i = 0; i < 3; i++) {
    ma = max(ma, abs(c[i] - m1));
  }
  cout << ma << endl;
  return 0;
}
