You could try this as a starting point:

=SUM(IF(FREQUENCY(IF(A1:A8<>"",IF(A1:A8<>"e",IF(A1:A8<>"f",MATCH(A1:A8,A1:A8,0)))),ROW(A1:A8)-ROW(A1)+1)>1,1))

confirmed with C+S+E.