#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define MAX 50
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


long long int fact(long long int n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(long long int n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

long long int gcd(long long int a,long long int b)
{
  if(a==0)
  return b;
  else
  return gcd(b%a,a);
}

long long int lcm(long long a,long long b)
{
    return (a*b)/gcd(a,b);
}

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

 
bool isSafe(int row, int col, int m[50][50],int n,int c, bool visited[50][50]) 
{ 
   if (row == -1 || row == n || col == -1 ||  col == c || visited[row][col] || m[row][col] == 0) 
        return false; 
  
    return true; 
} 
  
 
void printPathUtil(int row, int col, int m[50][50], int n,int c, string& path,vector<string>&possiblePaths, bool visited[][MAX]) 
{ 
    if (row == -1 || row == n || col == -1  
               || col == c || visited[row][col]  
                           || m[row][col] == 0) 
        return; 
  
    if (row == n - 1 && col == c - 1) { 
        possiblePaths.push_back(path); 
        return; 
    } 
    visited[row][col] = true; 

    if (isSafe(row + 1, col, m, n,c, visited)) 
    { 
        path.push_back('D'); 
        printPathUtil(row + 1, col, m, n,c, 
                 path, possiblePaths, visited); 
        path.pop_back(); 
    } 

    if (isSafe(row, col - 1, m, n,c, visited)) 
    { 
        path.push_back('L'); 
        printPathUtil(row, col - 1, m, n,c, 
                   path, possiblePaths, visited); 
        path.pop_back(); 
    } 

    if (isSafe(row, col + 1, m, n,c, visited))  
    { 
        path.push_back('R'); 
        printPathUtil(row, col + 1, m, n,c, 
                   path, possiblePaths, visited); 
        path.pop_back(); 
    } 

    if (isSafe(row - 1, col, m, n,c, visited)) 
    { 
        path.push_back('U'); 
        printPathUtil(row - 1, col, m, n,c, 
               path, possiblePaths, visited); 
        path.pop_back(); 
    } 

    visited[row][col] = false; 
} 
  

int printPath(int m[50][50], int n,int c,vector<pair<int,int>> good) 
{ 

    vector<string> possiblePaths; 
    int ans=0;
    string path; 
    bool visited[50][50]; 
    forp(i,0,50)
    forp(j,0,50)
    visited[i][j]=false;
    forp(i,0,good.size())
    {
    printPathUtil(good[i].F,good[i].S, m, n,c, path,  
                      possiblePaths, visited); 
    if(possiblePaths.size()==0)
    {
      ans=0;
      break;
    }
    else
    ans++;
    }
    
    return ans;
    
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
            long long int x,n,m,z=0,p=0,ans=INT_MAX,diff=INT_MAX;
            
              cin>>x>>n;
              vector<int> a(n),b(n);
              map<int,int> mp;
              if(n>0)
              {
              for(int i=0;i<n;i++)
              {
                cin>>m;
                mp[m]++;
                a.push_back(m);
              }
              sort(a.begin(),a.end());
int low=*(a.begin())-1,high=*(a.end()-1)+1;
z=0;
              while(low<=high)
              {
               // cout<<high<<" ";
                   if(mp[high]==0)
                   {
                     if(abs(x-high)<diff)
                     {
                       diff=abs(x-high);
                       
                       ans=high;
                   //  cout<<diff<<" "<<ans<<"\n";
                     }
                     else if(abs(x-high)==diff)
                     {
                       if(high<ans)
                       ans=high;
                     }
                   }
                   high--;
              }
              
              }
              else
              ans=x;
cout<<ans;
  cout<<"\n";
        
            
            
            
return 0;
}
            
            
            
            

Measured memory_bytes: 3648