a = gets.split(" ").map(&:to_i) array = Array.new(10, 0) a.each do | num | array[num] = 1 end array.each_with_index{|val,index| if(val == 0 and index != 0) then puts index break end }