#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int c = 0;
  while (arr[c + 1] > arr[c] && c < n - 1) {
    c++;
  }
  if (c == n - 1) {
    cout << "0 0" << endl;
    return 0;
  }
  int start = c;
  int ans2 = c;
  while (arr[c + 1] < arr[c] && c < n - 1) {
    c++;
  }
  int end = c;
  int ans1 = c;
  int temp;
  while (start < end) {
    temp = arr[start];
    arr[start] = arr[end];
    arr[end] = temp;
    start++;
    end--;
  }
  for (int i = 0; i < n - 1; i++) {
    if (arr[i + 1] < arr[i]) {
      cout << "0 0" << endl;
      return 0;
    }
  }
  cout << ans2 + 1 << " " << ans1 + 1 << endl;
  return 0;
}
