Yet Another Mex Problem

QOJ - 7605