LearnPy Hub
← Arena
EasyRating 1000

Ring Road

Houses 1..n stand on a one-way ring road; driving from house i to i + 1 takes one unit (and from n back to 1). Starting at house 1, you must do tasks at the given houses in order. Print the total time.

Input

n and m, then m house numbers.

Output

One integer.

Sample 1

Input
4 3
3 2 3
Output
6

Sample 2

Input
4 3
2 3 3
Output
2
solution.py
Output appears here
Ring Road · Python Arena problem · LearnPy Hub