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++ (GCC 9.2.1) (judge verdict: Accepted)

/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
    Date:13/06/2020
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)
ll mod=1000000007;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
bool test = 0;


void solve()
{
   
    int x,n;
    cin>>x>>n;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        int y;
        cin>>y;
        m[y]++;
    }
    int x1=-1,x2=-1;
    for(int i=x;i>=0;i--)
    {
        if(m[i]==0)
        {
            x1=i;
            break;
        }
    }
    for(int i=x+1;i<=101;i++)
    {
        if(m[i]==0)
        {
            x2=i;
            break;
        }
    }
    if(x1==-1 or x2==-1)
    {
        cout<<max(x1,x2);
        return;
    }
    if(abs(x1-x)==abs(x2-x))
    {
        cout<<min(x1,x2);
        return;
    }
    if(abs(x1-x)<abs(x2-x))
    cout<<x1;
    else
    cout<<x2;
    
    
}










signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}