Let $a_1, a_2, \ldots$ be a sequence defined by $a_1 = 1$ and for $n \ge 1$, $a_{n+1} = \sqrt{a_n^2 - 2a_n + 3} + 1$. Find $a_{513}$.

Let's think step by step and output the final answer within \boxed{}.
user