Concatenate the answer with smaller value of the topmost elements of both the stacks and then pop that element
if ( stack1 [ - 1 ] < stack2 [ - 1 ] ) : NEW_LINE INDENT ans = ans * 10 + stack1 [ - 1 ] NEW_LINE del stack1 [ - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT ans = ans * 10 + stack2 [ - 1 ] NEW_LINE del stack2 [ - 1 ] NEW_LINE DEDENT