#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e3 + 4;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, i, l = -1, r = -1, c = -1, d = -1;
  cin >> n;
  long long int a[n + 1];
  for (long long int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (long long int i = 1; i < n + 1; i++) {
    if (i != a[i]) {
      l = i;
      r = a[i];
      break;
    }
  }
  d = a[r];
  for (int i = r; i >= l; i--) {
    if (a[i] != d) {
      cout << "0 0";
      return 0;
    }
    d++;
  }
  for (long long int i = r + 1; i < n; i++) {
    if (a[i] != i) {
      cout << "0 0";
      return 0;
    }
  }
  if (l == -1) {
    cout << "0 0";
    return 0;
  }
  cout << l << " " << r;
  return 0;
}
