13. The answer is 2167. First, 2167 satisfies the required property with $S=2$: indeed

$$
\sqrt{2+\sqrt{1+\sqrt{6+\sqrt{7+2}}}}=\sqrt{2+\sqrt{1+\sqrt{6+\sqrt{9}}}}=\sqrt{2+\sqrt{1+\sqrt{9}}}=\sqrt{2+\sqrt{4}}=\sqrt{4}=2
$$

Now we show that there are no integers $n$ between 2016 and 2166 that have this property. We start by proving that $S$ must be less than 4. Indeed, if by contradiction $S \geq 4$, we would have

$$
S(S-1)>9 \Rightarrow S^{2}>S+9 \geq S+d \Rightarrow S>\sqrt{d+S}
$$

Similarly, we would have $S^{2}>S+9>\sqrt{d+S}+c \Rightarrow S>\sqrt{c+\sqrt{d+S}}$, and so on, leading to the contradiction $S>\sqrt{a+\sqrt{b+\sqrt{c+\sqrt{d+S}}}}=S$. We also observe that, since $S$ is an integer, all the arguments of the square roots must be perfect squares, and since we are looking for a number between 2016 and 2166, we must have $a=2$ and $b=0$ or $b=1$. We also have $S>1$, because $S>\sqrt{a} \geq 1$, and from $S \leq 3$ we find $d+S \leq 12$, from which $c+\sqrt{d+S} \leq 12$.

$d=7$. In this case, $c+\sqrt{d+S}=c+3$ must be a perfect square between 3 and 12, so $c=1$ or $c=6$. In the first case, $b+2$ is not a perfect square for $b=0,1$, while for $c=6$ we get that $b+3$ must be a square, which happens for $b=1$ and leads to the solution 2167.
13. Let $n$ be the smallest positive integer of 4 digits greater than or equal to 2016 that has the following property: there exists a positive integer $S$ such that

$$
S=\sqrt{a+\sqrt{b+\sqrt{c+\sqrt{d+S}}}}
$$

where $a, b, c, d$ are, in order, the thousands, hundreds, tens, and units digits of $n$. What is the value of $n$?