#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int in[N];
void solve() {
  int n;
  scanf("%d", &n);
  int l = 1e9, r = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &in[i]);
    if (in[i] != i) {
      l = min(l, i);
      r = max(r, i);
    }
  }
  if (l >= r) {
    printf("0 0 \n");
    return;
  }
  reverse(in + l, in + r + 1);
  for (int i = 1; i <= n; ++i) {
    if (in[i] != i) {
      printf("0 0\n");
      return;
    }
  }
  printf("%d %d\n", l, r);
}
int main() { solve(); }
