#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int main() {
  int n = 0, m[1 << 10], m1[1 << 10], num = 0, res = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> m[i];
  int p = 0;
  for (int k = 0; k < n; ++k)
    if (m[k] != k + 1) {
      p = 1;
      break;
    }
  if (!p) {
    cout << "0 0";
    return 0;
  }
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j <= n; ++j) {
      reverse(m + i, m + j);
      int p = 0;
      for (int k = 0; k < n; ++k)
        if (m[k] != k + 1) {
          reverse(m + i, m + j);
          p = 1;
          break;
        }
      if (p) continue;
      cout << i + 1 << " " << j;
      return 0;
    }
  cout << "0 0";
  return 0;
  ;
  "         ";
  ;
  "  -   *  ";
  ;
  "    |    ";
  ;
  "  \___   ";
  ;
  "         ";
}
