#include <bits/stdc++.h>
using namespace std;
int n;
int arr[1005];
int main() {
  cin >> n;
  int i;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int s = -1, e = -1;
  for (i = 0; i < n; i++) {
    if (arr[i] != i + 1) {
      s = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (arr[i] != i + 1) {
      e = i;
      break;
    }
  }
  if (s == -1 || e == -1) {
    cout << "0 0" << endl;
    return 0;
  }
  for (i = s; i <= e; i++) {
    if (arr[i] != e - (i - s - 1)) {
      cout << "0 0" << endl;
      return 0;
    }
  }
  cout << s + 1 << " " << e + 1 << endl;
}
