#include <bits/stdc++.h>
using namespace std;
int m[1001], m1[1001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
  }
  int index1 = 0, index2 = 0, cvet = 0;
  for (int i = 0; i < n; i++) {
    if (m[i] == i + 1)
      continue;
    else {
      index1 = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (m[i] == i + 1)
      continue;
    else {
      index2 = i;
      break;
    }
  }
  for (int i = index1 + 1; i <= index2; i++) {
    if (m[i] == m[i - 1] - 1)
      continue;
    else {
      cout << "0 0";
      return 0;
    }
  }
  if (index1 == index2)
    cout << "0 0";
  else
    cout << (index1 + 1) << " " << (index2 + 1);
  return 0;
}
