Each of Cossack Vus' m friends wants exactly three pies, meaning that all together they want 3m pies.
Since Cossack Vus gives away 3m out of his n pies, he's left with n−3m of them in the end. Thus, it suffices to print n−3m.