#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(const T &a) {
  return a * a;
}
template <typename T>
inline int nread(vector<T> &a) {
  int n;
  cin >> n;
  a.clear();
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  return n;
}
template <typename T>
inline void nwread(int n, vector<T> &a) {
  a.clear();
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
}
int main() {
  vector<int> a, b;
  int n = nread(a);
  int l = 0, r = n - 1;
  while (l < n && a[l] == l + 1) l++;
  if (l == n) {
    cout << "0 0";
    return 0;
  }
  while (a[r] == r + 1) r--;
  for (int i = 0; i < n; i++) b.push_back(i + 1);
  reverse(b.begin() + l, b.begin() + r + 1);
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      cout << "0 0";
      return 0;
    }
  }
  cout << l + 1 << ' ' << r + 1;
}
