first working solution of packing problem - not quite sure about termination condition 'exit'