#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long pow(long long b, long long e) {
  if (e == 0)
    return 1;
  else if (e % 2 == 0) {
    long long a = pow(b, e / 2);
    return a * a;
  } else {
    long long a = pow(b, e / 2);
    return b * a * a;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long tt = 1;
  for (long long i = 0; 0 < tt ? i < tt : i > tt; 0 < tt ? i += 1 : i -= 1) {
    long long n, R = 0, L = 0;
    cin >> n;
    vector<long long> arr(n + 1);
    for (long long i = 1; 1 < n + 1 ? i < n + 1 : i > n + 1;
         1 < n + 1 ? i += 1 : i -= 1) {
      cin >> arr[i];
      if (arr[i] != i) {
        R = i;
        if (L == 0) L = i;
      }
    }
    for (long long i = L, j = R; i <= R; i++, j--) {
      if (arr[i] != j) {
        cout << "0 0" << endl;
        return 0;
      }
    }
    cout << L << " " << R << endl;
  }
  return 0;
}
