Let $I$ be a closed interval in $\mathbb{R}$, and let $f:I \to \mathbb{R}$ be a bounded function, smooth except at finitely many points (piece-wise smooth). There are also only finitely many critical points, except that some of the pieces may be horizontal lines. [Edit: at any rate, I'm assuming $f$ has finitely many critical values in the codomain.] Let $$G = \operatorname{closure}\big(\{(x,y) \in I \times \mathbb{R} ~\big|~ y \leq f(x)\}\big)$$ denote the closed region under the graph of $f$. For each $s \in \mathbb{R}$, let $n(s)$ denote the number of connected components of the intersection of $G$ with the line $y=s$. In other words, the number of connected components of $\{(x,s) ~\big|~ s \leq f(x)\}.$
I would like a reference the following, which my intuition says is true and not difficult from the right perspective:
The function $n:\mathbb{R} \to \{0,1,2,3,\dots\}$ is continuous from below. That is, for any $s \in \mathbb{R}$, there exists $\varepsilon >0$ such that $n$ is constant on $(s-\varepsilon,s]$.
Here's a poor picture: (The vertical line segment in the boundary is at a place where $f$ had a discontinuity.)
A little context. This seems like a really elementary result (unless I'm dense and it's false as stated), but from an area that I'm not as comfortable with. I want to say it's like Morse theory for a 2-manifold with piece-wise smooth boundary in $\mathbb{R}^2$? But I'm not looking for a sledgehammer. I'm a number theorist, and this will be used in a number theory paper, and I guess that people reading (refereeing?) the paper might like a reference for this fact, even if it might be stated without proof or reference in papers in other fields. If you have a super short proof that would make sense to someone outside the area, that would be fine, too, of course.
Please help me improve this question if I've stated it poorly or tagged it inappropriately!