This question already has an answer here:
I'm following a proof in Jech's book that every well ordered set is isomorphic to a unique ordinal and hitting a point where I'm not sure why a certain move is justified. He writes
Proof. The uniqueness follows from Lemma 2.7. Given a well-ordered set $W$, we find an isomorphic ordinal as follows: Define $F(x) = \alpha$ if $\alpha$ is isomorphic to the initial segment of $W$ given by $x$. If such an $\alpha$ exists, then it is unique. By the Replacement Axioms, $ F(W) $ is a set. For each $x \in W$, such an $\alpha$ exists (otherwise consider the least $x$ for which such an $\alpha$ does not exist). If $\gamma$ is the least $\gamma \not\in F(W)$ then $F(W) =\gamma$ and we have an isomorphism of $W$ onto $\gamma$.
I've filled in all the details of this proof for myself up to the point where he assumes the class of ordinals not in the image of the function has a least element. Since this isn't a set, I'm not sure what can justify this. I could try to prove that every nonempty class of ordinals has a least element but that seems so substantial that it's hard to imagine it was a detail intentionally omitted. Am I missing something simple?