First, calculate the 3-base representation of m. e.g, if m=42 we will
get 1120.
Then find its last digit which is not zero. Obviously to make the 
scale balance you should put a weight to the left if the digit is 2
and to right otherwise. Then you have to update the value m to make 
it be the difference of the two arms. Do it until m is 0.

Since m may be very huge you have to use big number.