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