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 Go (1.14.1) (judge verdict: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
)

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}
func hasValue(val int, sl []int) bool {
	for x := 0; x < len(sl); x++ {
		if sl[x] == val {
			return true
		}
	}
	return false
}

//========== Implement Algorithm =======================
func solution(X int, p []int) int {
	sort.Ints(p)
	fullList := make([]int, 100-len(p))
	count := 0
	for i := 1; i < len(fullList); i++ {
		if !hasValue(i, p) {
			fullList[count] = i
			count++
		}

	}
	retVal := fullList[0]

	smallest := int(math.Abs(float64(X) - float64(fullList[0])))
	for x := 1; x < len(p); x++ {
		if smallest > int(math.Abs(float64(X)-float64(fullList[x]))) {
			retVal = fullList[x]
			smallest = int(math.Abs(float64(X) - float64(fullList[x])))
		}
	}
	return retVal
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var X, N, ret int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	X = fastGetInt(scanner.Bytes())
	scanner.Scan()
	N = fastGetInt(scanner.Bytes())
	p := make([]int, N)
	for x := 0; x < N; x++ {
		scanner.Scan()
		p[x] = fastGetInt(scanner.Bytes())
	}

	//======================================================
	ret = solution(X, p)
	//==================== OUTPUT ==========================
	fmt.Println(ret)
}