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.
n = int(input())
arr = [int(x) for x in input().split()]
reference = list(range(1, n+1))
difference = [arr[i] - reference[i] for i in range(n)]
# find first nonzero index of difference
first_nonzero = -1
for i in range(n):
	if(difference[i] != 0):
		first_nonzero = i
		break
# find last nonzero index of difference
last_nonzero = -1
for i in range(n-1, -1, -1):
	if(difference[i] != 0):
		last_nonzero = i
		break
if(first_nonzero == -1):
	# brother switched and someone switched it back, that someone wasn't Vasya
	print("0 0")
	exit()

# get reference list for specific part of the array that is switched
reference_part = list(range(first_nonzero+1, last_nonzero+2))[::-1]
tamper_evidence = [reference_part[i] - arr[first_nonzero:last_nonzero+1][i] for i in range(len(reference_part))]
for z in tamper_evidence:
	if(z != 0):
		# the array has been tampered with
		print("0 0")
		exit()
# the array has not been tampered with
print("%d %d"%(first_nonzero + 1, last_nonzero + 1))


# n = int(input())
# arr = [int(x) for x in input().split()]
# reverse_state = 0
# start = -1
# end = -1
# for i in range(n-1):
# 	print(reverse_state, start, end)
# 	if(arr[i+1] - arr[i] != 1):
# 		if(reverse_state == 0):
# 			reverse_state = 1
# 			start = i+2
# 		elif(reverse_state == 1 and arr[i+1] == i+2):
# 			# done
# 			end = i+1
# 		elif(arr[i+1] - arr[i] != -1):
# 			reverse_state = 2

# if(reverse_state != 1):
# 	print("0 0")
# else:
# 	print("%d %d"%(start, end))

# n = int(input())
# arr = [int(x) for x in input().split()]
# start = -1
# end = -1
# bad = 0
# for i in range(n):
# 	print(arr[i], i+1, start, end, bad)
# 	if(start != -1 and end == -1 and arr[i-1] - arr[i] != 1):
# 		bad = 1
# 		break
# 	if(arr[i] != i+1):
# 		if(start == -1):
# 			start = i
# 	else:
# 		if(end == -1 and start != -1):
# 			end = i-1

# if(end == -1):
# 	end = n

# if(start == -1 or bad == 1):
# 	print("0 0")
# else:
# 	print("%d %d"%(start+1, end+1))
