#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
const long double pi = 3.14159265359;
const long long INF = 1e8;
int n, a[N];
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  bool t = 0;
  int x1 = 0;
  int x2 = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      t = 1;
    }
  }
  if (!t) {
    cout << 0 << ' ' << 0;
    return 0;
  }
  for (int i = 1; i <= n - 1; i++) {
    if (a[i] > a[i + 1]) {
      x1 = i;
      break;
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    if (a[i] > a[i + 1]) {
      x2 = i + 1;
      break;
    }
  }
  vector<int> v, v2;
  for (int i = 1; i < x1; i++) {
    v.push_back(a[i]);
  }
  for (int i = x2; i >= x1; i--) {
    v.push_back(a[i]);
  }
  for (int i = x2 + 1; i <= n; i++) {
    v.push_back(a[i]);
  }
  int cnt = 0;
  for (auto i : v) {
    v2.push_back(i);
  }
  sort(v2.begin(), v2.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != v2[i]) {
      cout << "0 0";
      return 0;
    }
  }
  cout << x1 << ' ' << x2;
  return 0;
  for (int i = x1; i <= x2 - 1; i++) {
    if (a[i] < a[i + 1]) {
      cout << "0 0";
      return 0;
    }
  }
  cout << x1 << ' ' << x2;
}
