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)

//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
using namespace std::chrono;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n;--i)
#define pb push_back
#define m_p make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define present(c,x)    ((c).find(x) != (c).end())
#define count1 __builtin_popcount
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define mem(p,v) memset(p,(lli)v,sizeof p);
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
void show(vector<lli> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(vector<int> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(int a[], int arraysize)
{
    for (int i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(lli a[], lli arraysize)
{
    for (lli i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(unordered_set<int> s)
{
    for (auto it = s.begin(); it != s.end(); it++)
    {
        cout << *it << " ";
    }
    cout<<endl;
}
void show(unordered_map<int,int> mp)
{
    for (auto it = mp.begin(); it != mp.end(); it++)
    {
        cout << it->first << " "<<it->second<<endl;
    }
    cout<<endl;
}


int main()
{
    lli t,n,k,ans;
    t=1;
    while(t)
    {
        lli x;
        cin>>x>>n;
        lli a[n];
        fr(i,0,n)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        lli d=0,ans;
        while(d+x<INT_MAX&&x-d>INT_MIN)
        {
            lli ind=lower_bound(a, a+n, x-d)-a;
            if(a[ind]!=x-d)
            {
                ans=x-d;
                break;
            }
             ind=lower_bound(a, a+n, d+x)-a;
            if(a[ind]!=x+d)
            {
                ans=x+d;
                break;
            }
            d++;
        }
        cout<<ans<<endl;
        t--;
    }
    return 0;
}