Help with DP algorithm

I am looking for some guidance on how to go about constructing (and coding) and algorithm that solves the following puzzle:

There are 6 colors, randomly ascribed to the cells of an NxM grid. The goal is, beginning with the color in the upper-left corner (let's call it 0,0), change the entire grid to one solid color in the smallest number of turns. Adjacent cells with the same color become a blob, such that all connected cells of the same color as 0,0 will change.

My math skills are decent, but not graduate-level, and I am sure there is some existing complex algorithm out there that can be used. I just have no idea what it is, and might need a nudge in the right direction on how to apply it.