Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse order. That is, he took a certain segment [*l*, *r*] and reversed it. At that the segment's endpoints did not coincide. For example, if *n* = 8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2, 6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... *n* using exactly one segment reversal. If it is possible, find the segment itself.
The first line contains an integer *n* (1 ≤ *n* ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated *n* integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to *n*, and every number is used exactly 1 time.
#include<bits/stdc++.h>
 
using namespace std;
 
#define fIO ios::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define ull unsigned long long int
#define srt(s) sort (s.begin(),s.end() )
#define rsrt(s) sort (s.begin(),s.end() , greater <> ())
#define tc int t_;cin>>t_;while(t_--)
#define PI 2*acos(0)
#define tani(a) atan(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define cosi(a) acos(a)/(pi/180)
#define cos(a)  cos(a*pi/180)
#define sin(a)  sin(a*pi/180)
#define tan(a)  tan(a*pi/180)
#define mset(pq, v) memset(pq, v, sizeof(pq));
#define pb push_back
#define sp " "
#define sz(s) (int)(s).size()
#define LB lower_bound
#define UB upper_bound
#define fi(n) for(int i=0; i<n; i++)
#define fj(n) for(int j=0; j<n; j++)
#define FF first
#define SS second
#define CY cout<<"YES\n";
#define CN cout<<"NO\n";
#define CYR cout<<"YES\n";return;
#define CNR cout<<"NO\n";return;
#define C(s) cout<<s<<endl;
#define DBG cout << "DEBUG" << endl;
const ll M=1e9+7;
 
// int sum_digit(int x) { int sum=0; while(x>0){ sum+=x%10; x/=10; } return sum; }
// ll reverse_num(ll n){ ll tmp=n, ans=0, r; while(tmp>0){ r=tmp%10; ans=ans*10+r; tmp/=10; } return ans; }
// ll factorial(ll n){ ll i, ans=1; for(i=n; i>1; i--){ans*=i;} return ans; }
// ll gcd(ll num1, ll num2) { ll a,b,r; a=num1; b=num2; r=a%b; while(r>0){ a=b; b=r; r=a%b; } return b; }
// ll lcm(ll num1, ll num2) { return (num1*num2)/gcd(num1, num2); }
// bool prime(ll n) { if(n<2) return false; for(ll i=2;i<=sqrt(n);i++){ if(n%i==0)return false;} return true; }
// bool isSquare(ll x){ll sq=sqrt(x);return sq*sq==x;}
// ll mod_inverse(ll a, ll p, ll m){ ll r=1;while(p){if(p%2)r=((r%m)*(a%m))%m;a=((a%m)*(a%m))%m;p/=2;}return r;}
// ll POW(ll a,ll b){if(!b) return 1;ll r=POW(a,b/2);if(b%2) return r*r*a;else return r*r;}
// ll LOG2(ll n){ll v=1,c=0;while(v<=n)c++,v*=2;return c-1;}
 
// int dx[8] = {1, -1, 0,  0, 1,  1, -1, -1};
// int dy[8] = {0,  0, 1, -1, 1, -1,  1, -1};

// ll h=0;   
  

void solve (){
    
    ll n;
    cin>>n;
    vector<ll> v;
    fi(n){
      ll x;
      cin>>x;
      v.pb(x);
    }
    ll s=0,e=0;
    for(int i=0; i<n; i++){
      if(v[i]!=i+1){
        s=i+1;
        e=v[i];
        reverse(v.begin()+i, v.begin()+v[i]);
      break;
      }
    }
    
    bool flag=false;
    for(int i=0; i<n; i++){
     // cout<<v[i]<<" ";
      if(v[i]!=i+1)flag=true;
    }
   if(!flag)cout<<s<<" "<<e<<endl;
   else cout<<"0 0"<<endl;
}



int main()
{
   
        solve();
}