Vinnytsia Programmers' Amusements#4542

Vinnytsia Programmers' Amusements

0.1 seconds
16 megabytes
Medium

In recent years, Vinnytsia has become one of the most renowned cities in Ukraine thanks to its spectacular fountains. Tourists from all over the country, and sometimes even from abroad, come to see this colorful and unforgettable spectacle.

However, few know that Vinnytsia is also well known in the programming world. For instance, it hosts the annual NET-OI remote programming olympiad for schoolchildren. For twenty years, it has also hosted the "Tournament of Champions," a comprehensive olympiad for the winners and prize-winners of the All-Ukrainian school olympiads in mathematics, physics, and informatics. In recent years, the ACM Ukraine student final, which also serves as the semifinal for the World Student Programming Team Championship, has been held specifically in Vinnytsia.

It's only natural that when programmers meet, they combine business with pleasure and invent something unique. Indeed, during these kinds of events, programmers often organize trips to another Vinnytsia attraction—the Roshen chocolate factory. There, at the end of the tour, prizes provided by the producers of sweets are raffled off in an exciting fashion.

On a table, cups are arranged in a circle, each initially containing one candy. numbered programmer-tourists (hereafter referred to as players) stand by one of the cups on the table. Then each player chooses a number from to N-1. Players take turns in order. On each turn, a player moves clockwise around the table, counting cups until they have passed the number of cups they chose at the start of the game. They then take a candy (if one is present) from the cup where they stop. The game ends when all cups are empty. After this, the players eat the candies they've collected.

Write a program to help the -th player (the last to choose their number) pick a number that will allow them to collect as many candies as possible. Of course, they could do this themself, but at the moment they are busy eating sweets.

Input

The first line of the input contains two integers separated by a space: the number of cups and the number of players (1 \leq K < N < 100, and is prime). The second line contains K-1 integers in the range from to N-1, separated by spaces—these are the numbers chosen by the players numbered from to K-1.

Output

Print a single integer from to N-1 on the first line: the number that allows the -th player to collect the maximum number of candies. If there are multiple optimal choices, print the smallest one.

Examples

Example 1

Loading
Loading