write function check min