5. On the blackboard are the numbers $1,2, \cdots, 1987$. Perform the following transformation: erase some of the numbers on the blackboard and add the remainder when the sum of the erased numbers is divided by 7. After several such transformations, only two numbers remain on the blackboard, one of which is 987. Find the other number.
Note the fact that with each transformation: the sum of all numbers on the blackboard, when divided by 7, leaves the same remainder. $1+2+\cdots+1987=1987 \cdot 7 \cdot 142$, which indicates that the original sum on the blackboard is divisible by 7, so the sum of the two final numbers can also be divided by 7. Among the two final numbers, one of them (which cannot be 987) is the remainder when divided by 7, i.e., $0,1,2,3,4,5,6$. Since 987 is divisible by 7, the other number can only be 0.