I think that this will do what you need, array confirmed as beforeFormula:
=IFERROR(1/(1/MAX(FREQUENCY(IF(C4:LT4={"R";"M";"I"},COLUMN(C4:LT4)),IF(C4:LT4<>"R",IF(C4:LT4<>"M",IF(C4:LT4<>"I",COLUMN(C4:LT4))))))),"")
If you have to change , to ; for the formula to work with your regional settings, then you will most likely need to change the 2 ; already in the formula to \ in order to get the correct results.
Bookmarks