#include <bits/stdc++.h>
using namespace std;
int n, i, l, r, a[1013];
int main() {
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] != i) {
      if (l == 0) {
        l = i;
      } else {
        r = i;
      }
    }
  }
  for (i = l; i <= r; ++i) {
    if (a[i] != r + l - i) {
      l = 0;
      r = 0;
      break;
    }
  }
  cout << l << " " << r;
  return 0;
}
