The graph of the function $f$ is shown below. How many solutions does the equation $f(f(x))=6$ have?

[asy] import graph; size(200); defaultpen(fontsize(10pt)+linewidth(.8pt)); dotfactor=4;  pair P1=(-7,-4), P2=(-2,6), P3=(0,0), P4=(1,6), P5=(5,-6); real[] xticks={-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6}; real[] yticks={-6,-5,-4,-3,-2,-1,1,2,3,4,5,6};  draw(P1--P2--P3--P4--P5);  dot("(-7, -4)",P1); dot("(-2, 6)",P2,LeftSide); dot("(1, 6)",P4); dot("(5, -6)",P5);  xaxis("$x$",-7.5,7,Ticks(xticks),EndArrow(6)); yaxis("$y$",-6.5,7,Ticks(yticks),EndArrow(6)); [/asy]
The solutions to $f(x) = 6$ are $x = -2$ and $x = 1,$ so if $f(f(x)) = 6,$ then $f(x) = -2$ or $f(x) = 1.$

The line $y = -2$ intersects the graph of $y = f(x)$ twice, so the equation $f(x) = -2$ has two solutions.

The line $y = 1$ intersects the graph of $y = f(x)$ four times, so the equation $f(x) = -2$ has four solutions.

This gives us a total of $2 + 4 = \boxed{6}$ solutions.