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