for z in sorted(map(int,open('../fd/0')),key=lambda n:(sum(n/36**k%6**8==549305for k in range(99)),n)):print z