In
M Country, there are

cities and these cities are placed in one line, where the cities are labeled

one by one. Citizens in
M Country all use
MI-phones, and there are totally m network modes among the
MI-phones. For better management,
MI-phones in i-th city can only use

-th mode.
As a
MI fan, you want to experience all kind of network modes. So for each
)
, you want to find a shortest subinterval

in
M Country that all network modes from

to

are used at least once among the cities whose labels are in interval

, and we denote

as the length of the shortest subinterval. In this problem, you need to determine

.