#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n + 5];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l = 0, r = 0, cnt = 0;
  for (int i = 2; i <= n;) {
    l = i, r = i;
    while (a[i] < a[i - 1]) {
      r++;
      i++;
    }
    if (r != l) {
      sort(a + l - 1, a + r);
      break;
    }
    i++;
  }
  if (is_sorted(a + 1, a + n + 1) && l < r) {
    cout << l - 1 << " " << r - 1 << endl;
  } else {
    cout << "0 0" << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
