#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:136777216")
using namespace std;
int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); }
const double PI = acos(-1.0);
const double eps = 1e-9;
const int INF = 1000000000;
string nextString() {
  char buf[10000000];
  gets(buf);
  return buf;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  scanf("%d\n", &n);
  vector<int> in(n);
  for (int(i) = 0; (i) < (n); (i)++) scanf("%d", &in[i]);
  int l = -1;
  for (int(i) = 0; (i) < (n); (i)++)
    if (in[i] != i + 1) {
      l = i;
      break;
    }
  if (l == -1) {
    puts("0 0");
    return 0;
  }
  int r = in[l];
  for (int i = l, j = r; i < r; i++, j--)
    if (in[i] != j) {
      puts("0 0");
      return 0;
    }
  for (int(i) = (r); (i) < (n); (i)++)
    if (in[i] != i + 1) {
      puts("0 0");
      return 0;
    }
  printf("%d %d\n", l + 1, r);
  return 0;
}
