K=io.read"*n"

a={{}}
for i=1,9 do table.insert(a[1],{i}) end
function lunlun()
	local d=1
	while true do
		a[d+1]={}
		for i=1,#a[d] do
			local l=a[d][i][#a[d][i]]
			for k=math.max(0,l-1),math.min(9,l+1)do
				local b={}
				for j=1,d do
					table.insert(b,a[d][i][j])
				end
				table.insert(b,k)
				table.insert(a[d+1],b)
				coroutine.yield(b)
			end
		end
		d=d+1
	end
end

if(K<10)then print(K) return end

co=coroutine.create(lunlun)
for i=10,K do
	_,b=coroutine.resume(co)
end
print(table.concat(b))