#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, x = 0, y = 0, a[1001], b, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != i) {
      y = i;
      if (x == 0) x = i;
    }
  }
  for (i = x, j = y; i <= y; i++, j--) {
    if (a[i] != j) {
      cout << "0 0" << endl;
      return 0;
    }
  }
  cout << x << " " << y << endl;
  return 0;
}
