#include <bits/stdc++.h>
using namespace std;
int a[1010], b[1010];
int main() {
  int n;
  int t1 = 0, t2 = 0, num = 0;
  int k = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    if (a[i + 1] > a[i] + 1) {
      t1 = i + 1;
      num = a[i + 1];
      break;
    }
    if (a[i + 1] == a[i] - 1) {
      t1 = i;
      num = a[i];
      break;
    }
  }
  for (int i = t1 + 1; i <= n; i++) {
    if (a[i] == a[t1] + 1) {
      t2 = i - 1;
      break;
    }
    if (i == n && t2 == 0) {
      t2 = n;
      break;
    }
  }
  for (int i = t1; i < t2; i++)
    if (a[i] != a[i + 1] + 1) {
      k = 0;
      break;
    }
  for (int i = 1; i < t1 - 1; i++)
    if (a[i] + 1 != a[i + 1]) {
      k = 0;
      break;
    }
  for (int i = t2 + 1; i < n; i++)
    if (a[i] + 1 != a[i + 1]) {
      k = 0;
      break;
    }
  if (k == 0)
    cout << "0 0";
  else
    cout << t1 << " " << t2;
}
