#include <bits/stdc++.h>
using namespace std;
int a[1001], i, j, n, x, y;
bool b;
int main() {
  b = false;
  cin >> n;
  a[0] = 0;
  a[n + 1] = n + 1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == a[i - 1] + 1)
      continue;
    else {
      x = i;
      for (j = i + 1; j <= n + 1; j++)
        if (a[j] == a[j - 1] - 1)
          continue;
        else if (a[i] == a[j] - 1) {
          y = j - 1;
          break;
          break;
        } else {
          cout << "0 0";
          return 0;
        }
      break;
    }
  }
  for (i = x; i <= (y + x) / 2; i++) swap(a[i], a[y - i + x]);
  for (i = 1; i <= n; i++)
    if (a[i] != a[i - 1] + 1) b = true;
  if (b == false)
    cout << x << " " << y;
  else
    cout << "0 0";
  return 0;
}
