An integral formula for total gradient variation