#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> A(n);
  for (long long int i = 0; i < n; i++) {
    cin >> A[i];
  }
  bool is = false;
  int start;
  for (int i = 0; i < n; i++) {
    if (A[i] != i + 1) {
      start = i;
      is = true;
      break;
    }
  }
  if (!is) {
    cout << "0 0\n";
  } else {
    int where = -1;
    for (int i = start + 1; i < n; i++) {
      if (A[i] == start + 1) {
        where = i;
        break;
      }
    }
    is = true;
    reverse(A.begin() + start, A.begin() + where + 1);
    for (int i = start; i < where; i++) {
      if (A[i] != i + 1) {
        is = false;
        break;
      }
    }
    if (!is) {
      cout << "0 0\n";
    } else {
      is = true;
      for (int i = where + 1; i < n; i++) {
        if (A[i] != i + 1) {
          is = false;
          break;
        }
      }
      if (is) {
        cout << start + 1 << " " << where + 1 << endl;
      } else {
        cout << "0 0\n";
      }
    }
  }
  return (0);
}
