#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int count = 0;
  int s = -1, e = -1;
  for (int i = 0; i < n - 1; i++) {
    if (abs(a[i + 1] - a[i]) != 1 && count == 0) {
      s = i + 2;
      count++;
    } else if (abs(a[i + 1] - a[i]) != 1 && count == 1) {
      e = i + 1;
      count++;
    } else if (abs(a[i + 1] - a[i]) != 1)
      count++;
  }
  if (n == 2 && a[0] == 2)
    cout << "1 2";
  else if (count == 1) {
    e = n;
    if (a[n - 1] == s)
      cout << s << " " << e;
    else
      cout << "0 0";
  } else if (count == 2) {
    cout << s << " " << e;
  } else
    cout << "0 0";
  return 0;
}
