#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
int n, a[1100];
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    a[i]--;
  }
  int l = n - 1, r = -1;
  for (int i = 0; i < (int)(n); i++)
    if (a[i] != i) {
      l = min(l, i);
      r = max(r, i);
    }
  if (r == -1) {
    cout << "0 0\n" << endl;
    return 0;
  }
  reverse(a + l, a + r + 1);
  for (int i = 0; i < (int)(n); i++)
    if (a[i] != i) r = -1;
  if (r == -1) {
    cout << "0 0\n" << endl;
    return 0;
  }
  cout << l + 1 << " " << r + 1 << endl;
  return 0;
}
