#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<pair<int, int> > pos;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == i + 1)
      ;
    else {
      pos.push_back(make_pair(a[i] - i - 1, i + 1));
    }
  }
  if (pos.size() == 0 || pos.size() & 1) {
    cout << "0 0\n";
    return 0;
  }
  bool flg = pos[0].first > 0;
  for (int i = 0; i < pos.size() / 2; i++) {
    if (pos[i].first < 0 && flg || pos[i].first > 0 && !flg ||
        pos[i].first != -pos[pos.size() - i - 1].first) {
      cout << "0 0\n";
      return 0;
    }
  }
  cout << min(pos.back().second, pos[0].second) << " "
       << max(pos.back().second, pos[0].second) << endl;
  return 0;
}
