#include <bits/stdc++.h>
using namespace std;
int n, m, i, a[1005], b[1005], Id[1005];
int ans, ans1, ans2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
    Id[b[i]] = i;
  }
  sort(a + 1, a + n + 1);
  i = 1;
  while (i <= n) {
    if (a[i] != b[i]) {
      m = Id[a[i]];
      for (int j = i + 1; j <= m; j++)
        if (b[j] != b[j - 1] - 1) {
          printf("0 0\n");
          return 0;
        }
      ans++;
      ans1 = i;
      ans2 = m;
      i = m;
    }
    i++;
  }
  if (ans != 1)
    printf("0 0\n");
  else
    printf("%d %d\n", ans1, ans2);
  return 0;
}
