if __name__ == '__main__': test_data = input() # test_data = 'dbcacbca' output = '' visual = [0, ] * 256 record = [0, ] * 256 # build record for vl in test_data: record[ord(vl)] = record[ord(vl)] + 1 # filter for vl in test_data: record[ord(vl)] = record[ord(vl)] - 1 if visual[ord(vl)] == 1: continue while len(output) > 0 and output[-1] > vl and record[ord(output[-1])] > 0: visual[ord(output[-1])] = 0 output = output[:-1] output = output + vl visual[ord(vl)] = 1 print(output)