P27588 [洛谷] [Language Contest 202301] Lightning Rods
普及-
题目描述

Problem Description

$n$ lightning rods are arranged in a row from left to right, numbered sequentially as $1$ to $n$.

There are $m$ lightning strikes occurring in sequence. You are given a sequence $a_1, \cdots, a_m$. For the $i$-th lightning strike, it hits the lightning rods numbered $a_i - 2$ (if it exists), $a_i - 1$ (if it exists), $a_i$, $a_i + 1$ (if it exists), and $a_i + 2$ (if it exists).

After all $m$ lightning strikes, you want to know how many lightning rods have been hit at least once.

Input Format

The input consists of two lines.

The first line contains two integers $n, m$, representing the number of lightning rods and the number of lightning strikes, respectively.

The second line contains $m$ integers $a_1, \cdots, a_m$, representing the sequence mentioned in the problem.

Output Format

The output consists of one line.

Output a single integer, the number of lightning rods that have been hit at least once.

Sample Input and Output

Sample Input #1

17 1
4

Sample Output #1

5

Sample Input #2

10 1
2

Sample Output #2

4

Sample Input #3

9 3
3 7 7

Sample Output #3

9

Notes

Sample 1 Explanation

The lightning rods hit are numbered $2, 3, 4, 5, 6$, totaling $5$.

Sample 2 Explanation

The lightning rods hit are numbered $1, 2, 3, 4$, totaling $4$. Note that the lightning rod numbered $a_1 - 2 = 0$ does not exist and should not be hit.

Sample 3 Explanation

The lightning rods hit are numbered $1, 2, 3, 4, 5, 6, 7, 8, 9$, totaling $9$.

Note that although some lightning rods were hit two or three times, we count each of these only once.

Data Range and Constraints

  • For the first $10\%$ of the data, $n = 1$ is guaranteed.
  • For the first $30\%$ of the data, $m = 1$ is guaranteed.
  • For another $20\%$ of the data, $m \leq n - 2$ and $\forall i \in [1, m], a_i = i$ are guaranteed.
  • For $100\%$ of the data, $1 \leq n, m \leq 10^6$ and $1 \leq a_i \leq n$ are guaranteed.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
17 1 4
样例输出
5