package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { var input = bufio.NewScanner(os.Stdin) var output int var digits []int for input.Scan() { line := input.Text() digits = []int{} values := strings.Split(line, " ") for _, v := range values { d, _ := strconv.Atoi(v) digits = append(digits, d) } output = missingNumber(digits) fmt.Println(output) } } func missingNumber(nums []int) int { var length = len(nums) if length-1 == nums[length-1] { return length } var left, right = 0, len(nums) - 1 var mid int for left < right { mid = (left + right) / 2 if nums[mid] > mid { right = mid } else { left = mid + 1 } } return left }