Let $S$ be the set of all positive integers from 1 through 1000 that are not perfect squares. What is the length of the longest, non-constant, arithmetic sequence that consists of elements of $S$?

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