#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, temp = 0;
  int flag = 0, index1 = 0, index2 = 0;
  std::vector<int> v, v1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    v.push_back(temp);
    v1.push_back(i + 1);
  }
  for (int i = 0; i < n - 1; i++) {
    if (v[i] - v[i + 1] != 1 && v[i] > v[i + 1]) {
      cout << 0 << "	" << 0 << "	" << endl;
      return 0;
    }
    if (v[i] - v[i + 1] == 1 && flag == 0) {
      index1 = i + 1;
      while (v[i] - v[i + 1] == 1 && i < n - 1) {
        i++;
      }
      flag = 1;
      index2 = i + 1;
    } else if (flag == 1 && v[i] > v[i + 1]) {
      cout << 0 << "	" << 0 << "	" << endl;
      return 0;
    }
  }
  if (flag == 1)
    cout << index1 << "	" << index2 << "	" << endl;
  else
    cout << 0 << "	" << 0 << "	" << endl;
  return 0;
}
