I need to find the MOST consecutive times a color occures in column C before it occures in column E if column F says "color"

Example ...
-C----E----F
xxx red
red xxx color
xxx red color
red xxx color
xxx xxx color
xxx xxx
red xxx color
red xxx
xxx xxx color
red xxx color
xxx xxx color
xxx red color
red xxx color
xxx xxx color

answer for red should be 3

I've tried this formula ...
=SUM(IF((F2:F5000="color"),(--(MODE(COUNTIF(INDIRECT("E"&ROW(INDIRECT("E2:E5000"))&":E5000"),C5024))=IF(C2:C5000=C5024,COUNTIF(INDIRECT("E"&ROW(INDIRECT("E2:E5000"))&":E5000"),C5024))))))
where C5024=red, but for some reason it's not always accurate.

Is there another 1 cell formula I can try? Or what's causing my current formula to not always work correctly? Thanks, John