Balance the equations: you could use some kind of diophantine equation solver. There's probably some elegant solutions out there. But this is homework for human beings. Coefficients are likely to be low. Brute force shouldn't be too bad in this case.