#???????????¢?????¢???(search0)
#??????????°???????????????????????°???????????????????????????????????????????????????±???????????¢?´¢???????????°??????

def search rest
	if rest == []
		return true
	end
	if rest.count(rest[0]) > 2
		if search(rest[3..-1])
			return true
		end
	end
	if rest.index(rest[0] + 1) && rest.index(rest[0] + 2)
		nex = rest.dup
		nex.slice!(nex.index(rest[0]))
		nex.slice!(nex.index(rest[0]+1))
		nex.slice!(nex.index(rest[0]+2))
		if search(nex)
			return true
		end
	end
	return false
end

def search0 rest
	1.upto(9){|i|
		if rest.count(i) > 1
			nex = rest.dup
			nex.slice!(nex.index(i))
			nex.slice!(nex.index(i))
			if search(nex)
				return true
			end
		end
	}
	return false
end

while gets
	s = $_.chomp.chars.map &:to_i
	ans = []
	1.upto(9){|i|
		unless s.count(i) == 4
			if search0((s+[i]).sort)
				ans << i
			end
		end
	}
	if ans == []
		puts 0
	else
		puts ans*" "
	end
end