Except for the first two terms, each term of the sequence $1000,x,1000-x,\ldots$ is obtained by subtracting the preceding term from the one before that. The last term of the sequence is the first negative term encountered. What positive integer $x$ produces a sequence of maximum length?