#include <bits/stdc++.h>
using namespace std;
inline void JadedBeast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  JadedBeast();
  int n;
  cin >> n;
  int a;
  vector<int> v1, vn;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a == 1) v1.push_back(i);
    if (a == n) vn.push_back(i);
  }
  sort(vn.begin(), vn.end());
  sort(vn.begin(), vn.end());
  int x = abs(n - v1[0]), y = abs(vn[0] - n);
  int w = abs(1 - v1[v1.size() - 1]), z = abs(1 - vn[vn.size() - 1]);
  cout << max({x, y, w, z}) << endl;
  return 0;
}
