added a function to calculate the lowest class after perfoming the substitutions.