#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, fidx = -1, lidx = -1;
  cin >> n;
  vector<int> v(n + 1, 0);
  for (i = 0; i < n; i++) cin >> v[i];
  for (i = 0; i < n; i++) {
    if (v[i] != (i + 1)) {
      fidx = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (v[i] != i + 1) {
      lidx = i;
      break;
    }
  }
  if (fidx < 0) {
    cout << "0 0" << endl;
    return 0;
  }
  if (lidx < 0) {
    cout << "0 0" << endl;
    return 0;
  }
  reverse(v.begin() + fidx, v.begin() + lidx + 1);
  for (i = 0; i < n; i++) {
    if (v[i] != (i + 1)) {
      cout << "0 0" << endl;
      return 0;
    }
  }
  cout << fidx + 1 << " " << lidx + 1 << endl;
  return 0;
}
