#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l = 1e9, r = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 1; i <= n; i++) {
    cin >> a[i - 1];
    if (a[i - 1] != i) {
      l = min(l, i);
      r = max(r, i);
    }
  }
  bool ok = true;
  reverse(a.begin() + l - 1, a.begin() + r);
  for (int i = 1; i <= n; i++) {
    if (i != a[i - 1]) {
      ok = false;
      break;
    }
  }
  if (ok && l < 1e9)
    cout << l << " " << r << endl;
  else
    cout << "0 0" << endl;
}
