#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++)
    for (int j = i + 2; j <= n; j++) {
      reverse(&a[i], &a[j]);
      int f = 0;
      for (int k = 0; k < n; k++) {
        if (a[k] != b[k]) f = 1;
      }
      reverse(&a[i], &a[j]);
      if (f == 0) {
        cout << i + 1 << " " << j;
        return (0);
        ;
      }
    }
  cout << "0 0";
}
