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.