Minimizing gauge functional for 2d gravity and string theory