Language: C++

#include <bits/stdc++.h>
using namespace std;

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define FOR(i, a, b) for (int i = a; i <= (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i >= (int)(b); i--)

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using Lint = long long;
#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define PB push_back
#define MP make_pair
using P=pair<int, int>;
using V=vector<int>;
using M=map<int, int>;
using S=set<int>;

#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "

#define DUMP(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
/* vector<T>のイテレータはvector<T>::iterator型
vector<int>::iterator it = vc.begin();  // begin()はvectorの最初の要素を指すイテレータを返す。
vector<int>::iterator endIt = vc.end(); // end()はvectorの終端位置を指すイテレータを返す。
while (it != endIt)
{
  cout << *it << '\n'; // イテレータの指す要素は、ポインタのように*演算子でアクセスします。
  it++;                // インクリメントすることで次の要素を指します。
}
}*/
int main()
{
  
  int x,n,aa=1,f=-1;
  cin>>x>>n;
  V a(n);
  REP(i,n)cin>>a[i];
  int b=100;
  while(b){
    REP(i,n){
  		if(x==a[i])
  		{x-=aa;
  		aa++;
  		aa*=f;
  		f*=(-1);
  		}
	 }
    b--;
  }
  COUT(x);
  /*  vector<P> abs_v(n);

    REP(i,n){
    abs_v[i].second=a[i];
	abs_v[i].first=abs(x-a[i]);
  }
 // sort(abs_v.begin(),abs_v.end());

  REP(i,n){#include <bits/stdc++.h>
using namespace std;

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define FOR(i, a, b) for (int i = a; i <= (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i >= (int)(b); i--)

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using Lint = long long;
#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define PB push_back
#define MP make_pair
using P=pair<int, int>;
using V=vector<int>;
using M=map<int, int>;
using S=set<int>;

#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "

#define DUMP(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
/* vector<T>のイテレータはvector<T>::iterator型
vector<int>::iterator it = vc.begin();  // begin()はvectorの最初の要素を指すイテレータを返す。
vector<int>::iterator endIt = vc.end(); // end()はvectorの終端位置を指すイテレータを返す。
while (it != endIt)
{
  cout << *it << '\n'; // イテレータの指す要素は、ポインタのように*演算子でアクセスします。
  it++;                // インクリメントすることで次の要素を指します。
}
}*/
int main()
{
  
  int x,n,aa=1,f=-1;
  cin>>x>>n;
  V a(n);
  REP(i,n)cin>>a[i];
  int b=1000;
  int tmp=1;
  while(b){
    REP(i,n){
  		if(x==a[i])
  		{x-=tmp;
  		aa++;
  		tmp=aa*(-1);
  		}
	 }
    b--;
  }

  COUT(x);
  /*  vector<P> abs_v(n);

    REP(i,n){
    abs_v[i].second=a[i];
	abs_v[i].first=abs(x-a[i]);
  }
 // sort(abs_v.begin(),abs_v.end());

  REP(i,n){
  int aa=1;
    int f=-1;
    REP(j,n){
      
      REP(k,n){
        if(abs_v[i].second==a[j]){
        abs_v[i].second-=aa;
          aa++;
          aa*=(f);
          f*=(-1);
          
        }	
      }
    }
  }
   //    sort(abs_v.begin(),abs_v.end());
  if(n==0)COUT(x);
  else {COUT(abs_v[0].second);
        COUT(abs_v[1].second);
          COUT(abs_v[2].second);
        COUT(abs_v[3].second);
        COUT(abs_v[4].second);;
       } */
  
  
}
  int aa=1;
    int f=-1;
    REP(j,n){
      
      REP(k,n){
        if(abs_v[i].second==a[j]){
        abs_v[i].second-=aa;
          aa++;
          aa*=(f);
          f*=(-1);
          
        }	
      }
    }
  }
   //    sort(abs_v.begin(),abs_v.end());
  if(n==0)COUT(x);
  else {COUT(abs_v[0].second);
        COUT(abs_v[1].second);
          COUT(abs_v[2].second);
        COUT(abs_v[3].second);
        COUT(abs_v[4].second);;
       } */
  
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:113:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  113 | int main()
      |         ^~
a.cc:113:9: note: remove parentheses to default-initialize a variable
  113 | int main()
      |         ^~
      |         --
a.cc:113:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:114:1: error: a function-definition is not allowed here before '{' token
  114 | {
      | ^
a.cc:169:7: error: redeclaration of 'int aa'
  169 |   int aa=1;
      |       ^~
a.cc:46:11: note: 'int aa' previously declared here
   46 |   int x,n,aa=1,f=-1;
      |           ^~
a.cc:170:9: error: redeclaration of 'int f'
  170 |     int f=-1;
      |         ^
a.cc:46:16: note: 'int f' previously declared here
   46 |   int x,n,aa=1,f=-1;
      |                ^
a.cc:174:12: error: 'abs_v' was not declared in this scope; did you mean 'abs'?
  174 |         if(abs_v[i].second==a[j]){
      |            ^~~~~
      |            abs
a.cc:174:18: error: 'i' was not declared in this scope
  174 |         if(abs_v[i].second==a[j]){
      |                  ^
a.cc: At global scope:
a.cc:185:3: error: expected unqualified-id before 'if'
  185 |   if(n==0)COUT(x);
      |   ^~
a.cc:186:3: error: expected unqualified-id before 'else'
  186 |   else {COUT(abs_v[0].second);
      |   ^~~~
a.cc:191:11: error: expected unqualified-id before '/' token
  191 |        } */
      |           ^
a.cc:194:1: error: expected declaration before '}' token
  194 | }
      | ^