main = readLn >>= print.(lunlun!!).pred where
 lunlun = [1..9]++concatMap f lunlun
 f x
  | r == 0 = [x*10, x*10+1]
  | r == 9 = [x*10+8, x*10+9]
  | otherwise = [x*10+r-1..x*10+r+1]
  where r = mod x 10

