#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a[1005], x1, x2;
  scanf("%d", &n);
  a[0] = 0;
  a[n + 1] = n + 1;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  x1 = x2 = 0;
  for (i = 1; i <= n; i++) {
    if (a[i - 1] == i - 1 && a[i] != i && x1 == 0) x1 = i;
    if (a[i] != i && a[i + 1] == i + 1) x2 = i;
  }
  for (i = x1; i <= x2; i++)
    if (a[i] + i != x1 + x2) {
      x1 = x2 = 0;
      break;
    }
  printf("%d %d\n", x1, x2);
  return 0;
}
