Set $M=\{1,2,\ldots,1000\}$. For any $X\subseteq M$ ($X\neq\varnothing$), define $a_X$ as the sum of the minimum and maximum numbers in $X$. Determine the arithmetic mean of all $a_X$.

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