#include <bits/stdc++.h>
using namespace std;
double epsilon = 0.0000001f;
long long mod = 1e9 + 7;
double Pi = acos(-1);
void print(vector<long long> V) {
  cout << "\n---------------Vector checking start-------------------\n";
  long long sz = V.size();
  for (int i = 0; i < sz; i++) {
    cout << V[i] << "  ";
  }
  cout << "\n----------------Vector checking end--------------------\n";
}
void print(long long arr[], long long n) {
  cout << "\n---------------Array checking start-------------------\n";
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }
  cout << "\n----------------Array checking end--------------------\n";
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  }
  long long testCase = 1;
  while (testCase--) {
    long long n, m, k, x, y, z, a, b, c, d, mn, mx, temp, cnt, ans, sum, sz,
        len;
    cin >> n;
    long long arr[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    a = -1;
    for (int i = 1; i <= n; i++) {
      if (arr[i] != i) {
        a = i;
        break;
      }
    }
    if (a == -1) {
      cout << 0 << " " << 0 << "\n";
      return 0;
    }
    for (int i = n; i >= a; i--) {
      if (arr[i] != i) {
        b = i;
        break;
      }
    }
    x = a, y = b;
    while (a < b) {
      temp = arr[b];
      arr[b] = arr[a];
      arr[a] = temp;
      a++, b--;
    }
    for (int i = 1; i <= n; i++) {
      if (arr[i] != i) {
        cout << 0 << " " << 0 << "\n";
        return 0;
      }
    }
    cout << x << " " << y << "\n";
  }
  return 0;
}
