#include <bits/stdc++.h>
using namespace std;
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
long long i, j;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, count = 0, flag = 0, loc;
    cin >> n;
    vector<long long> v(n + 1);
    v[0] = 0;
    for (i = 1; i <= n; i++) {
      cin >> v[i];
      if (v[i] == i) {
        count++;
      }
    }
    if (count == n) {
      cout << "0 0";
      return 0;
    } else {
      for (i = 1; i <= n; i++) {
        if (v[i] != i) {
          loc = v[i];
          break;
        }
      }
      long long loc2 = i;
      reverse(v.begin() + loc2, v.begin() + loc + 1);
      for (i = 1; i <= n; i++) {
        if (v[i] != i) {
          cout << "0 0";
          return 0;
        }
      }
      cout << loc2 << " " << loc;
    }
  }
}
