Inna is an avid hiker. She's visiting a range of $n$ mountains with heights $h_1, h_2, \ldots, h_n$.

At a nearby shop, Inna has found a book that mentions that at some point in the past, the heights of the mountains were $p_1, p_2, \ldots, p_n$ in the same order. However, there is no evidence of how old this book is.

The book also describes a model of erosion that makes the mountains shorter year after year. Every year, based on the weather, a certain height threshold $x$ can be determined. Then, every mountain with the current height of at least $x$ decreases in height by exactly $1$. Different years can have different values of $x$.

Inna is curious how old the book actually is, and whether the described model is sound. Help her figure out the smallest number of years in which erosion could take the mountains from heights $p_1, p_2, \ldots, p_n$ to heights $h_1, h_2, \ldots, h_n$ in the same order, or determine that it is impossible under the given model.