#include <bits/stdc++.h>
using namespace std;
int const inf = 1000000000;
int main() {
  vector<int> V;
  V.clear();
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    V.push_back(a);
  }
  for (i = 0; i < n; i++) {
    if (V[i] != i + 1) break;
  }
  int a = i;
  for (i = n - 1; i >= 0; i--) {
    if (V[i] != i + 1) break;
  }
  int b = i;
  reverse(V.begin() + a, V.begin() + b + 1);
  for (i = 0; i < V.size(); i++)
    if (V[i] != i + 1) break;
  if (a >= b || i < V.size()) {
    cout << "0 0\n";
  } else
    cout << a + 1 << " " << b + 1 << endl;
  return 0;
}
