P6022 Soda

Background

Little W is going to buy soda.

Description

He arrives in front of a shop. To attract customers to buy soda, the shop runs the following promotion: “Exchange $5$ bottle caps for one bottle of soda.” So people come to the shop to buy soda. After buying soda, he thinks of a question: Suppose one bottle of soda comes with $m$ accessories. For the $i$-th accessory, every $a_i$ of them can be exchanged for one brand-new bottle of soda. Now I have enough money to buy $n$ bottles of soda. What is the maximum number of sodas I can drink?

Input Format

The first line contains two integers $n,m$, with the meanings described above. The next line contains $m$ integers $a_1,a_2,\cdots,a_m$, with the meanings described above.

Output Format

If Little W can get soda for free infinitely, output one line containing the string `Inf`. Otherwise, output one line containing an integer $s$, which is the maximum number of sodas Little W can drink.

Explanation/Hint

Explanation for Sample 1: | Step | Drunk | Undrunk | Accessory 1 | Accessory 2 | | ---- | ----- | ------- | ----------- | ----------- | | 1 | 0 | 5 | 0 | 0 | | 2 | 5 | 0 | 5 | 5 | | 3 | 5 | 3 | 1 | 1 | | 4 | 8 | 0 | 4 | 4 | | 5 | 8 | 3 | 0 | 0 | | 6 | 11 | 0 | 3 | 3 | | 7 | 11 | 1 | 1 | 3 | | 8 | 12 | 0 | 2 | 4 | | 9 | 12 | 2 | 0 | 0 | | 10 | 14 | 0 | 2 | 2 | | 11 | 14 | 1 | 0 | 2 | | 12 | 15 | 0 | 1 | 3 | Explanation for Sample 2: | Step | Drunk | Undrunk | Accessory 1 | Accessory 2 | | ---- | -------- | -------- | ----------- | ----------- | | 1 | 0 | 2 | 0 | 0 | | 2 | 2 | 0 | 2 | 2 | | 3 | 2 | 2 | 0 | 0 | | 4 | 4 | 0 | 2 | 2 | | 5 | 4 | 2 | 0 | 0 | | 6 | 6 | 0 | 2 | 2 | | 7 | 6 | 2 | 0 | 0 | | 8 | 8 | 0 | 2 | 2 | | 9 | $\vdots$ | $\vdots$ | $\vdots$ | $\vdots$ | It is obvious that Little W can keep getting soda for free infinitely like this. **Note: In this problem, we assume you cannot borrow/repay or buy on credit.** Constraints: Test Point 1 is the same as Sample 2. For $30\%$ of the testdata, $n\le 100$, $m\le 2$. For $100\%$ of the testdata, $1\le n\le 10^4$, $1\le m\le 5$, $1\le a_i\le 2\times10^3$. Translated by ChatGPT 5