#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 30;
int main() {
  int x, n;
  int i1 = 0, i2 = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == 1) i1 = i;
    if (x == n) i2 = i;
  }
  if (i2 > i1) swap(i1, i2);
  int ans = i1 - i2 + max(n - i1, i2 - 1);
  cout << ans;
  return 0;
}
