In Griffiths' E&M, there is an equation that describes energy of a charge distribution as-
$W = \frac{\epsilon_0}{2}\int(\nabla.\textbf{E})V d\tau$
The author then performs integration by parts to get-
$W = \frac{\epsilon_0}{2}[-\int \textbf{E}.(\nabla V)d\tau + \oint V\textbf{E}.d\textbf{a} ]$
I understand that the right side of the equation comes from using the Divergence theorem, but I am unable to figure out how exactly the left side appears.