#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> mas(n, 0);
  int prev;
  scanf("%d", &mas[0]);
  prev = mas[0];
  int s = -1, f = -1;
  for (int i = 1; i < n; ++i) {
    scanf("%d", &mas[i]);
    if (mas[i] < prev) {
      if (s == -1) {
        s = i - 1;
      }
      prev = mas[i];
    } else if (s != -1 && mas[i] > prev) {
      if (f == -1) {
        f = i - 1;
      }
    }
    prev = mas[i];
  }
  if (s != -1 && f == -1) {
    f = n - 1;
  }
  if (s != -1 && f != -1) reverse(mas.begin() + s, mas.begin() + f + 1);
  for (int i = 1; i < n; ++i) {
    if (!(mas[i] > mas[i - 1])) {
      cout << "0 0";
      return 0;
    }
  }
  cout << s + 1 << " " << f + 1;
  return 0;
}
