#D. 环上距离

    Type: Default 1000ms 256MiB

环上距离

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Background

Special for beginners, ^_^

Description

有一个周长为 K 米的圆环,环上有 N 个房子。 第 i 个房子在原点位置沿着顺时针方向0走 ai 米的位置。 问从某一个房子开始,沿着圆环走(顺时针或者逆时针),走过所有房子,最少要走多少米。

Format

Input

第一行2个整数,K 和 N.

接着有 N 个整数,表示每一个房子的位置。

Output

最少要走多少米。

Samples

输入1

20 3
5 10 15

输出1

10

解释1

从第1个房子开始走,走过第2个,第三个。 走的距离为10

输入2

20 3
0 5 15

输出2

10

解释2

从第3个房子开始走,走到第1个,再走到第2个。 总共走的距离为10.

Limitation

2K106 2 \le K \le 10^6

2N2105 2 \le N \le 2* 10^5

0aiK0 \le a_i \le K

初二上学期期中考试

Not Attended
Status
Done
Rule
IOI
Problem
4
Start at
2022-11-7 14:30
End at
2022-11-7 16:00
Duration
1.5 hour(s)
Host
Partic.
108