Integrability of two-loop dilatation operator in gauge theories