Fix the G-code and remove the extra material change

Hello everyone! The problem is as follows: I’m printing a part, and on the top layer (1 or 2), I want to paint half of the part, but there are 8 layers to paint, which is unnecessary time and material changes.

Basically, I need to paint the area I’ve selected in the number of layers I’ve chosen.



I only need the top layer, but you can see in the photo that there are several layers underneath. How can I avoid this? Applying a layer of paint did not help remove it