CF538C Tourist's Notes

题目描述

一位旅行者沿着山脉远足,一共 $n$ 天,每天他都记下来这一天他所在的海拔高度。任意两天所在的海拔高度之差不会超过 $1$。形式化来说,令第 $i$ 天的海拔高度为 $h_i$,则 $h_i-h_{i-1}| \leq 1 $。 几十年后,旅行者回忆这段时光时发现他丢失了一些当时的日记,他现在只有 $m$ 天高度的记录。 现在这位旅行者想知道,根据残存的 $m$ 天海拔记录,他当年最高可能达到过多高的海拔。

输入格式

第一行两个整数 $n$ 和 $m$。 接下来 $m$ 行,每行两个正整数,$d_i$ 和 $h_{d_i}$ ,表示 $d_i$ 天,他的海拔为 $h_{d_i}$,且保 证 $d_i>d_i-1$。

输出格式

一行一个数表示答案,假如残存的海拔记录存在矛盾,则输出 ```IMPOSSIBLE```。 Translate by [BYWYR](https://www.luogu.com.cn/user/128221)

说明/提示

For the first sample, an example of a correct height sequence with a maximum of 2: $ (0,0,1,2,1,1,0,1) $ . In the second sample the inequality between $ h_{7} $ and $ h_{8} $ does not hold, thus the information is inconsistent.