Dehn's algorithm for the word problem