#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];
  bool possible = 1;
  int situation = 0, start, end = -1;
  for (int i = 1; i < n; i++) {
    if (!situation) {
      if (arr[i] == arr[i - 1] + 1)
        continue;
      else if (arr[i] > arr[i - 1]) {
        situation = 1;
        start = i;
      } else if (arr[i] == arr[i - 1] - 1) {
        situation = 1;
        start = i - 1;
      } else
        possible = 0;
    } else if (situation == 1) {
      if (arr[i] == arr[i - 1] - 1)
        continue;
      else if (arr[i] > arr[i - 1]) {
        situation = 2;
        end = i - 1;
      } else
        possible = 0;
    } else {
      if (arr[i] == arr[i - 1] + 1)
        continue;
      else
        possible = 0;
    }
  }
  if (!possible || !situation)
    cout << "0 0";
  else if ((start > 0 && end < n - 1 && end > -1 &&
            arr[start] == arr[end + 1] - 1 && arr[end] - 1 == arr[start - 1]) ||
           (start > 0 && end == -1 && arr[start - 1] == arr[n - 1] - 1) ||
           (!start && end > -1 && end < n - 1 &&
            arr[start] == arr[end + 1] + 1) ||
           (!start && end == -1))
    cout << start + 1 << " " << (end == -1 ? n : end + 1);
  else
    cout << "0 0";
  return 0;
}
