#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int arr[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int x = 0, t = 0;
  int u = 0, v = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] != i + 1 || (i > 0 && arr[i - 1] - 1 == arr[i])) {
      if (x == 0) t++;
      if (x == 0 && t > 1) {
        cout << "0 0\n";
        return 0;
      } else if (x == 0 && t == 1) {
        u = i + 1;
        x = 1;
      } else {
        if (arr[i - 1] - 1 != arr[i]) {
          cout << "0 0\n";
          return 0;
        }
        x = 1;
      }
    } else {
      if (x == 1) v = i;
      x = 0;
    }
  }
  if (u != 0 && v == 0) v = n;
  cout << u << " " << v << endl;
}
