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 Rust (1.42.0) (judge verdict: Wrong Answer)

use proconio::input;
use std::ops::{Add, Div};
 
pub fn binary_search<T: Add<Output = T> + Div<Output = T> + PartialEq + From<u8> + Copy>(
    l: T,
    r: T,
    pred: impl Fn(T) -> bool,
) -> T {
    let mut l = l;
    let mut r = r;
    let two = T::from(2_u8);
    loop {
        let m = (l + r) / two;
        if l == m || r == m {
            break l;
        }
        if pred(m) {
            l = m;
        } else {
            r = m;
        }
    }
}
    
pub fn upper_bound<T: PartialOrd>(v: &[T], val: &T) -> usize {
    (binary_search(-1, v.len() as i64, |i: i64| v[i as usize] <= *val) + 1) as usize
}

pub fn lower_bound<T: PartialOrd>(v: &[T], val: &T) -> usize {
    (binary_search(-1, v.len() as i64, |i: i64| v[i as usize] < *val) + 1) as usize
}

fn main() {
    input! {
        (x, n): (u64, u64),
        ps: [u64; n]
    }

    let ps : Vec<u64> = ps.to_vec();
    let mut v : Vec<u64> = (1..=100u64).collect();

    for i in ps {
        if let Some(pos) = v.iter().position(|a| *a == i){
            v.remove(pos);
        }
    }
   
    let ans = lower_bound(&v[..], &x);

    let mut a: i64 = 100;
    if let Some(n) = v.get(ans - 1) {
        a = *n as i64;
    }

    let mut b: i64 = 100;
    if let Some(n) = v.get(ans) {
        b = *n as i64;
    }

    let abs1 = (x as i64 - a).abs();
    let abs2 = (x as i64 - b).abs();

    if abs1 <= abs2 {
        println!("{}", a);
        return;
    } else if abs1 > abs2 {
        println!("{}", b);
        return;
    } 
}