#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[1000];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int i;
  for (i = 0; i < n; i++) {
    if (arr[i] != (i + 1)) break;
  }
  int start = i;
  i = 0;
  for (i = n - 1; i >= 0; i--) {
    if (arr[i] != (i + 1)) break;
  }
  int end = i;
  if (start == n && end == -1) {
    cout << "0 0" << endl;
    return 0;
  }
  for (int j = start, k = end; j < k; j++, k--) {
    swap(arr[j], arr[k]);
  }
  for (i = 0; i < n; i++) {
    if (arr[i] != (i + 1)) {
      cout << "0 0" << endl;
      return 0;
    }
  }
  cout << start + 1 << " " << end + 1 << endl;
  return 0;
}
