#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  int t[2000], v[2000];
  for (int i = 0; i < n; i++) {
    cin >> x;
    v[i] = x;
  }
  if (is_sorted(v, v + n)) {
    cout << 0 << " " << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      memcpy(t, v, sizeof(v));
      reverse(t + i, t + j + 1);
      if (is_sorted(t, t + n)) {
        cout << i + 1 << " " << j + 1;
        return 0;
      }
    }
  }
  cout << 0 << " " << 0;
}
