Jon wrote the $n$ smallest perfect squares on one sheet of paper, and the $n$ smallest triangular numbers on another sheet (note that $0$ is both square and triangular). Jon notices that there are the same number of triangular numbers on the first paper as there are squares on the second paper. However, if $n$ had been one smaller, this would not have been true. If $n < 2008$, let $m$ be the greatest number Jon could have written on either paper. Find the remainder when $m$ is divided by $2008$.

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