#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
int a[maxn];
const int mod = 1e9 + 7;
char L[200], R[200];
map<int, int> m;
long long gcd(long long a, long long b) {
  if (a == 0)
    return 0;
  else {
    long long k = b / a;
    return k + gcd(b % a, a);
  }
}
string getnum(string code) {
  int res = 0;
  int d = 1;
  for (int i = (int)code.length() - 1; i >= 0; i--) {
    res += d * (code[i] - 'A' + 1);
    d *= 26;
  }
  return to_string(res);
}
string d[maxn];
string getcode(int n) { return d[n]; }
void precalc() {
  d[1] = "A";
  for (int i = 2; i < maxn; i++) {
    string s = d[i - 1];
    int c = 1;
    for (int j = 0; j < s.length(); j++) {
      int curc = s[j] - 'A';
      int newc = curc + c;
      if (newc == 26) {
        newc = 0;
        c = 1;
        s[j] = 'A';
      } else {
        s[j] = 'A' + newc;
        c = 0;
        break;
      }
    }
    if (c == 1) s += 'A';
    d[i] = s;
  }
  for (int i = 1; i < maxn; i++) {
    reverse(d[i].begin(), d[i].end());
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int one = find(a, a + n, 1) - a;
  int nth = find(a, a + n, n) - a;
  if (one > nth) swap(one, nth);
  cout << max(n - one - 1, nth - 0) << endl;
}
