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