CF182B.Vasya's Calendar

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya lives in a strange world. The year has nn months and the ii -th month has aia_{i} days. Vasya got a New Year present — the clock that shows not only the time, but also the date.

The clock's face can display any number from 11 to dd . It is guaranteed that ai<=da_{i}<=d for all ii from 11 to nn . The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d+1d+1 , so after day number dd it shows day 11 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day dd is also followed by day 11 .

Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.

A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the nn -th month inclusive, considering that on the first day of the first month the clock display showed day 11 .

输入格式

The first line contains the single number dd — the maximum number of the day that Vasya's clock can show (1<=d<=106)(1<=d<=10^{6}) .

The second line contains a single integer nn — the number of months in the year (1<=n<=2000)(1<=n<=2000) .

The third line contains nn space-separated integers: aia_{i} (1<=ai<=d)(1<=a_{i}<=d) — the number of days in each month in the order in which they follow, starting from the first one.

输出格式

Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.

输入输出样例

  • 输入#1

    4
    2
    2 2
    

    输出#1

    2
    
  • 输入#2

    5
    3
    3 4 3
    

    输出#2

    3
    
  • 输入#3

    31
    12
    31 28 31 30 31 30 31 31 30 31 30 31
    

    输出#3

    7
    

说明/提示

In the first sample the situation is like this:

  • Day 1. Month 1. The clock shows 11 . Vasya changes nothing.
  • Day 2. Month 1. The clock shows 22 . Vasya changes nothing.
  • Day 1. Month 2. The clock shows 33 . Vasya manually increases the day number by 11 . After that the clock shows 44 . Vasya increases the day number by 11 manually. After that the clock shows 11 .
  • Day 2. Month 2. The clock shows 22 . Vasya changes nothing.

In total, Vasya manually changed the day number by 11 exactly 22 times.

首页