#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 0, b = 0, c = 0, d = 0, n, temp, dl;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    if (i < n) {
      cin >> temp;
    } else {
      temp = max(a, d) + 1;
    }
    dl = temp - a;
    if (dl != 1 && dl != -1) {
      if (!b) {
        b = i + 1;
        d = temp;
      } else if (!c) {
        c = i;
      } else {
        b = 0;
        c = 0;
        break;
      }
    } else if (!c && b) {
      if (dl != -1) {
        b = 0;
        c = 0;
        break;
      }
    }
    a = temp;
  }
  cout << b << ' ' << c;
}
