#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int i, p = 0, n, a, p1 = 0;
  cin >> n;
  vector<int> v;
  vector<int> v1;
  vector<int> v2;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    if (a != i + 1) {
      v2.push_back(i);
    }
  }
  v1 = v;
  sort(v1.begin(), v1.end());
  if (v2.size() > 0) {
    p = v2[0], p1 = v2[v2.size() - 1];
    reverse(v.begin() + p, v.begin() + (p1 + 1));
  }
  if (v == v1 && v2.size() > 0) {
    cout << p + 1 << " " << p1 + 1;
  } else {
    cout << "0 0";
  }
  return 0;
}
