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)

//
//AtCoder Beginner Contest 170
//C - Forbidden List
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int x, n;
    cin >> x >> n;

    vector<int> p(n);
    REP(i, n) cin >> p[i];

    int u = -1;
    int l = -1;
    FOR(i, x, 101){
        bool f=true;
        REP(j, n){
            if (i == p[j]) {
                f=false;
                break;
            }
        }
        if (f){
            u=i;
            break;
        }
    }
    FORD(i, x-1, 0){
        bool f=true;
        REP(j, n){
            if (i == p[j]) {
                f=false;
                break;
            }
        }
        if (f){
            l=i;
            break;
        }
    }

    if (abs(x-u) >= abs(x-l)){
        cout << l << endl;
    }else {
        cout << u << endl;
    }

/*
    ll mv = 999999999;
    FOR(i, 1, 100){
        bool flag = true;
        REP(j,n){
            if (i == p[j]) {
                flag = false;
                break;
            }
        }
        if (flag){
            mv = min(mv, abs(x-i));
        }
    }
    bool f=false;
    REP(i,n){
        if (p[i]==x-mv) f=true;
    }
    if (f) cout << x+mv << endl;
    else cout << x-mv << endl;
*/
    return 0;
}