#include <bits/stdc++.h>
using namespace std;
int dist(int a[], int n, int l, int r) {
  int pa = 0, pb = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == l) pa = i;
    if (a[i] == r) pb = i;
  }
  return abs(pa - pb);
}
void copy(int n, int a[], int b[]) {
  for (int i = 0; i < n; ++i) b[i] = a[i];
}
int main() {
  int n;
  scanf("%d", &n);
  int a[128], b[128], c[128];
  int pa, pb;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == 1) pa = i;
    if (a[i] == n) pb = i;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    copy(n, a, b);
    copy(n, a, c);
    swap(c[pb], c[i]);
    swap(b[pa], b[i]);
    ans = max(ans, dist(c, n, 1, n));
    ans = max(ans, dist(b, n, 1, n));
  }
  cout << ans << "\n";
}
