Understanding the linear expenditure system
For every $x_i$ separately you get

$$\frac {\gamma_i}{x_i-a_i} = \lambda p_i \tag{1}$$

Re-arranging,

$$\frac {\gamma_i}{\lambda} = p_ix_i - p_ia_i \tag{2}$$

Sum over $i$

$$\frac 1{\lambda}\sum\gamma_i = \sum p_ix_i - \sum p_ia_i \tag{3}$$

Re-arrange to solve for the optimal $\lambda$ taking into account the restrictions

$$\sum p_ix_i = m ,\;\;\; \sum\gamma_i=1$$

$$\lambda^* = \frac {1}{m-\sum p_ia_i}\tag {4}$$

Insert into $(2)$, re-arrange and you 're done.