What is the maximum value of $n$ for which there is a set of distinct positive integers $k_1, k_2, \ldots, k_n$ such that
$k^2_1 + k^2_2 + \ldots + k^2_n = 2002?$

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