#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> arr(n, 0);
  vector<int> sorted(n, 0);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sorted = arr;
  sort(sorted.begin(), sorted.end());
  int l = -1;
  int r = -1;
  for (int i = 0; i < n; i++) {
    if (arr[i] != sorted[i]) {
      l = arr[i];
      r = i + 1;
      break;
    }
  }
  if (l != -1) {
    for (int i = r - 1, j = l - 1; j > r, i < l; i++, j--) {
      if (sorted[i] != arr[j]) {
        l = 0;
        r = 0;
        break;
      }
    }
    for (int i = l; i < n; i++) {
      if (sorted[i] != arr[i]) {
        l = 0;
        r = 0;
        break;
      }
    }
  } else {
    l = 0;
    r = 0;
  }
  cout << r << " " << l << endl;
  return 0;
}
