s=gets.chomp c=0 n=s[0].to_i b=8 j=true s.length.times do |i| g=s[i].to_i if g%2==0 b=g if b>g && g!=0 else b=1 end if j && g%5==0 j=true else j=false end if n!=-1 && n!=g n=-1 end c+=g end cc=1 loop do if c%3==0 c/=3 cc*=3 else break end end j=j ? 5:1 if n!=-1 puts s else puts b*cc*j end