#include <bits/stdc++.h>
using namespace std;
int n, a[1000];
void f(int l, int r) {
  int b[1000];
  for (int i = l; i <= r; i++) b[i] = a[l + r - i];
  for (int i = l; i <= r; i++) a[i] = b[i];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int t = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != i + 1) t = 1;
  if (t == 0) {
    cout << 0 << " " << 0;
    return 0;
  }
  for (int l = 0; l < n; l++) {
    for (int r = l + 1; r < n; r++) {
      f(l, r);
      int t = 0;
      for (int i = 0; i < n; i++)
        if (a[i] != i + 1) t = 1;
      if (t == 0) {
        cout << l + 1 << " " << r + 1;
        return 0;
      }
      f(l, r);
    }
  }
  cout << 0 << " " << 0;
  return 0;
}
