#include <bits/stdc++.h>
int main() {
  int i, n, x, y, z;
  int a[2000];
  int one, end;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  x = 0;
  y = 0;
  z = 0;
  for (i = 1; i < n; i++) {
    if ((a[i] > a[i + 1]) && (a[i] - a[i + 1] == 1)) {
      x = i + 1;
      y++;
    }
  }
  one = x - y;
  end = x;
  for (i = one; i <= end; i++) a[i] = i;
  for (i = 1; i <= n; i++) {
    if (a[i] == i) z++;
  }
  if ((z == n) || (one == 1 && end == n))
    printf("%d %d", one, end);
  else
    printf("0 0");
  return 0;
}
