#include <bits/stdc++.h>
using namespace std;
int mx, i, j, l, r, p2, p, n, a[10110];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  i = 2;
  p = a[1];
  mx = 0;
  while (i <= n) {
    j = i + 1;
    if (p - 1 == a[i]) {
      j = i + 1;
      p2 = a[i];
      while (j <= n && p2 - 1 == a[j]) {
        p2 = a[j];
        j++;
      }
      if (j - i > mx) {
        mx = j - i;
        l = i - 1;
        r = j - 1;
      }
    }
    p = a[i];
    i = j;
  }
  p = a[r];
  for (i = l; i <= r; i++) {
    a[i] = p;
    p++;
  }
  bool boo = true;
  for (i = 2; i <= n; i++)
    if (a[i] != a[i - 1] + 1) boo = false;
  if (!boo) {
    cout << "0 0";
    return 0;
  }
  printf("%d %d", l, r);
  return 0;
}
