#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int l, r;
bool flag;
int main() {
  int n;
  cin >> n;
  int a[n + 2];
  a[n + 1] = -10;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i + 1] == a[i] - 1) {
      int k = i;
      l = k;
      while (a[k] == a[k + 1] + 1) k++;
      r = k;
      break;
    }
  reverse(a + l, a + r + 1);
  for (int i = 1; i <= n; i++)
    if (a[i] != i) {
      cout << "0 0";
      return 0;
    }
  cout << l << " " << r;
}
