#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > Q;
const int INF = 1e9 + 9;
long int pow(long int a, long int b, int m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  int ar[n + 5];
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  int ans[n + 5];
  for (int i = 1; i <= n; i++) {
    ans[i] = i;
  }
  int k = 0, c = 0;
  int ind = 0;
  int si = 0;
  for (int i = 1; i <= n; i++) {
    if (ar[i] != ans[i]) {
      c++;
      si = i;
      for (k = i; k <= n; k++, i++) {
        if (ar[k + 1] > ar[k]) {
          ind = k;
          break;
        }
      }
    }
  }
  if (c > 1) {
    cout << 0 << " " << 0 << endl;
  }
  bool flag = true;
  for (int j = k + 1; j <= ind; j++) {
    if (ar[j] != ar[j - 1] - 1) {
      flag = false;
      cout << 0 << " " << 0 << endl;
      return 0;
    }
  }
  if (flag and c == 1) {
    cout << si << " " << ind << endl;
  }
  if (c == 0) {
    cout << 0 << " " << 0 << endl;
  }
}
