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: Wrong Answer)

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;

 ll mod=1e9 +7;


const ll M=200006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

int main()
{

	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
 //    #endif

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();

    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	int i,j,x,n,ans,val=102;
    	cin>>x>>n;
    	int a[101]={0};
    	for(i=0;i<n;i++)
    	{
    		cin>>j;
    		a[j]++;
    	}
    	for(i=x;i<=100;i++)
    	{
    		if(a[i]>0) continue;
    		if(val>i-x)
    		{
    			val=i-x;
    			ans=i;
    		}
    		break;
    	}
    	for(i=x;i>=0;i--)
    	{
    		if(a[i]>0) continue;
    		if(val>x-i)
    		{
    			val=x-i;
    			ans=i;
    		}
    		break;
    	}
    	if(val>101-x) {val=101-x;ans=101;}
    	if(val>x+1) {ans=-1;}
    	cout<<ans;



    }

	return 0;
}