If present value is less than next value , subtract present from next value and add the resultant to the sum variable .
if ( m [ str [ i ] ] < m [ str [ i + 1 ] ] ) { sum += m [ str [ i + 1 ] ] - m [ str [ i ] ] ; i ++ ; continue ; } sum += m [ str [ i ] ] ; } return sum ; }