#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = 0; i < n; ++i) {
    if (v[i] != i + 1) {
      for (int j = n - 1; j >= 0; --j) {
        if (v[j] != j + 1) {
          reverse(begin(v) + i, begin(v) + j + 1);
          for (int k = i; k <= j; ++k) {
            if (v[k] != k + 1) goto __bad;
          }
          cout << i + 1 << ' ' << j + 1 << endl;
          return 0;
        }
      }
    }
  }
__bad:
  cout << "0 0\n";
  return 0;
}
