#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
void pre() {
  cout.setf(ios::fixed);
  cout.precision(20);
  cerr.setf(ios::fixed);
  cerr.precision(3);
}
void post() {
  fprintf(stderr, "\n");
  fprintf(stderr, "Execution time: %Lf", (long double)clock());
}
const int MAXN = 100100;
int a[222222];
pair<int, int> b[222222];
vector<int> ans;
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first < b.first;
}
vector<int> pos;
inline bool sort_(int l, int r) {
  int cnt = 0;
  for (int i = l + 1; i <= r; i++)
    if (a[i] < a[i - 1]) cnt++;
  if (cnt == r - l || cnt == 0) return true;
  return false;
}
inline void solve(int test_number) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int c1 = 0;
  int ind = n - 1, ind1 = n - 1;
  for (int i = 0; i < n - 1; i++)
    if (a[i] > a[i + 1]) {
      ind = i;
      break;
    }
  for (int i = n - 1; i >= 1; i--)
    if (a[i - 1] > a[i]) {
      ind1 = i;
      break;
    }
  if (ind == n - 1) {
    printf("%d %d", 0, 0);
    return;
  }
  reverse(a + ind, a + ind1 + 1);
  if (sort_(0, n - 1)) {
    printf("%d %d", ind + 1, ind1 + 1);
    return;
  }
  printf("%d %d", 0, 0);
  return;
}
int main() {
  pre();
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  post();
  return 0;
}
