Initialized cost to max value.