#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  if (!(~ch)) return 0;
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  int x = 0;
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int a[1001], b[1001];
int main() {
  int n = read();
  for (register int i = 1; i <= n; ++i) a[i] = b[i] = read();
  sort(b + 1, b + n + 1);
  int x = 0;
  for (register int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      x = i;
      break;
    }
  }
  int y = 0;
  for (register int i = n; i; --i) {
    if (a[i] != b[i]) {
      y = i;
      break;
    }
  }
  for (register int i = y; i > x; --i)
    if (a[i] + 1 != a[i - 1]) {
      puts("0 0");
      return 0;
    }
  printf("%d %d\n", x, y);
  return 0;
}
