for(;a=readline();)print((495-parseInt(a,18)).toString(18))