Let $S_0=0$ and let $S_k$ equal $a_1+2a_2+\ldots+ka_k$ for $k\geq 1$.  Define $a_i$ to be $1$ if $S_{i-1}<i$ and $-1$ if $S_{i-1}\geq i$.  What is the largest $k\leq 2010$ such that $S_k=0$?

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