#include <bits/stdc++.h>
using namespace std;
int a, b[1009], l, r, c[1009];
bool d;
int main() {
  cin >> a;
  for (int i = 1; i <= a; i++) cin >> b[i], c[i] = b[i];
  sort(c + 1, c + a + 1);
  for (int i = 1; i <= a; i++) {
    if (b[i] > i and d == 0)
      d = 1, l = i;
    else if (d == 1 and b[i] == i and b[i + 1] == i + 1) {
      r = i - 1;
      break;
    }
  }
  d = 0;
  if (l > 0 and r == 0) r = a;
  reverse(b + l, b + r + 1);
  for (int i = 1; i <= a; i++)
    if (c[i] != b[i]) {
      d = 1;
      break;
    }
  if (d == 0)
    cout << l << ' ' << r << endl;
  else
    cout << 0 << ' ' << 0 << endl;
  return 0;
}
