Problem:
Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using static System.Console;
using static Atcoder_Template_NetCore3.MyUtil;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.IO;

namespace Atcoder_Template_NetCore3
{
    class Program
    {
        static void Main()
        {
            var (target, length) = ReadInt2();
            int[] input = length == 0 ? (ReadLine() == "" ? new int[0] : throw new Exception()) : ReadintArray();
            var koho = Enumerable.Range(-1, 103).Where(x => !input.Contains(x));
            var ans = koho.Where(x => Math.Abs(target - x) == koho.Select(y => Math.Abs(target - y)).Min()).Min();
            WriteLine(ans);
        }
    }

    static class MyUtil
    {
        /// <summary>
        /// 指定の桁のビットを取得します。
        /// </summary>
        /// <param name="num"></param>
        /// <param name="count">取得する桁。</param>
        /// <returns></returns>
        public static int GetBit(this int num, int count)
        {
            int mask = (int)Math.Pow(2, count - 1);
            return (num & mask) == 0 ? 0 : 1;
        }

        /// <summary>
        /// <c>int</c>を2進数ビット配列に変換します。
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static int[] ToBitArray(this int num)
        {
            const int size = sizeof(int) * 8;
            var array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = num.GetBit(size - i);
            }
            return array;
        }

        #region AutoGeneratedCode 整数読み取り系
        public static ValueTuple<int, int> ReadInt2()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1]);
        }
        public static ValueTuple<long, long> ReadLong2()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1]);
        }
        public static ValueTuple<int, int, int> ReadInt3()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1], input[2]);
        }
        public static ValueTuple<long, long, long> ReadLong3()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1], input[2]);
        }
        public static ValueTuple<int, int, int, int> ReadInt4()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3]);
        }
        public static ValueTuple<long, long, long, long> ReadLong4()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3]);
        }
        public static ValueTuple<int, int, int, int, int> ReadInt5()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4]);
        }
        public static ValueTuple<long, long, long, long, long> ReadLong5()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4]);
        }
        public static ValueTuple<int, int, int, int, int, int> ReadInt6()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4], input[5]);
        }
        public static ValueTuple<long, long, long, long, long, long> ReadLong6()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4], input[5]);
        }
        public static ValueTuple<int, int, int, int, int, int, int> ReadInt7()
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4], input[5], input[6]);
        }
        public static ValueTuple<long, long, long, long, long, long, long> ReadLong7()
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            return (input[0], input[1], input[2], input[3], input[4], input[5], input[6]);
        }
        #endregion
        /// <summary>
        /// 標準入力からスペース区切りの数値を <see cref="int"/> 配列として読み取ります。
        /// </summary>
        /// <returns></returns>
        public static int[] ReadintArray()
        {
            return ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }

        /// <summary>
        /// 標準入力からスペース区切りの数値を <see cref="long"/> 配列として読み取ります。
        /// </summary>
        /// <returns></returns>
        public static long[] ReadlongArray()
        {
            return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        }

        /// <summary>
        /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ts"></param>
        public static void WriteToConsole<T>(this IEnumerable<T> ts)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (T t in ts)
            {
                stringBuilder.Append(t.ToString());
                stringBuilder.Append(" ");
            }
            stringBuilder.Remove(stringBuilder.Length - 1, 1);
            Console.WriteLine(stringBuilder.ToString());
        }
    }
}