#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cur = 0, prev, pos1 = 0, pos2 = 0;
  bool no = false;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; ++i) {
    prev = cur;
    scanf("%d ", &cur);
    if (no) continue;
    if (!pos2 && cur > prev + 1) {
      pos1 = i;
      pos2 = cur;
      continue;
    }
    if (pos2) {
      if (i <= pos2 && prev != cur + 1)
        no = true;
      else if (i - 1 == pos2 && prev != pos1)
        no = true;
      else if (i > pos2 + 1 && cur != prev + 1)
        no = true;
    }
  }
  if (no) pos1 = pos2 = 0;
  printf("%d %d", pos1, pos2);
  return 0;
}
