#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
  int n, l = 0, r = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] != i) {
      l = i;
      break;
    }
  for (int i = n; i; i--)
    if (a[i] != i) {
      r = i;
      break;
    }
  bool c = true;
  for (int i = r - 1; i >= l && c; i--)
    if (a[i] != a[i + 1] + 1) c = false;
  if (c)
    cout << l << " " << r;
  else
    cout << "0 0";
  return 0;
}
