AT the end there are equal number of $2 and $5 notes and their total amount is $511. Let 'x' be the number of notes of $2 and $5.
So 2x + 5x =511, thus x = 73.
In the end there are 73 pieces of $2 and 73 pieces of $5.
So in the beginning, there are 73-2 = 71 pieces of $5, and 73+5 =78...