Another MEX Problem

CodeForces - 1870E