#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn], n;
int abs(int x) {
  if (x < 0) x = -1 * x;
  return x;
}
int solve() {
  int st = 0, ed = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) st = i;
    if (a[i] == n) ed = i;
  }
  return abs(ed - st);
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        swap(a[i], a[j]);
        int sum = solve();
        ans = max(ans, sum);
        swap(a[i], a[j]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
