Prove that the level sets of a continous function $f:S\in\mathbb{R}^m\rightarrow\mathbb{R}$ are closed in S I need help with this problem:

Let $f:S\in\mathbb{R}^m\rightarrow\mathbb{R}$ be continuous. Prove that the level sets of f are closed in S.

I know that for a real valued function $f:S\in\mathbb{R}^m\rightarrow\mathbb{R}$ to be continous on $\mathbf{p}\in S$ means that if $f(\mathbf{a_k})\rightarrow f(\mathbf{p})$ then $\mathbf{a_k}\rightarrow \mathbf{p}$. $\mathbf{a_k}\in S$.
I also know that a level set corresponding to c is $f^{-1}(c)=\{\mathbf{x}\in S |f(\mathbf{x})=c\}$. I don't know how to use this two definitios to prove the  above statement. Please help me.
 A: If $x_n \in f^{-1} (c)$ and $x_n \to x$ then $f(x_n)=c$ for all $n$ so (taking limit) $f(x)=c$ or $x \in f^{-1}(c)$. So $f^{-1}(c)$ is closed. 
A: Consider a level set $\{ \mathbf{x}\ | \ f( \mathbf{x}) = c \}$.  The set $\{c \} \subset \mathbb{R}$ is closed$^\dagger$, and the function $f: \mathbb{R}^n \to \mathbb{R}$ is continuous.  This means that the preimage of any open set in $\mathbb{R}$ is also open in $\mathbb{R}^n$.  The trick is knowing / recognizing that this definition of continuity can be rephrased like so:

Lemma: If $g:X \to Y$ is a continuous function, then the preimage of any closed subset of $Y$ is also closed in $X$.
Proof: Let $V \subset Y$ be a closed set.  Its complement $Y \setminus V$ is open, which means $W = \{g^{-1}(Y \setminus V) \}$ is open in $X$ per the original definition of continuity.  Because $W$ is open, $X \setminus W$ is closed.  And notice that $X \setminus W$ is the same set as $\{ g^{-1}(V) \}$, so the preimage of a closed set $V \subset Y$ is closed in $X$.

Here, because $f$ is continuous and $\{c\}$ a closed set, the preimage (level set) is also closed.

$^\dagger$ You can see this a couple ways.  Clearly, $\{c\}$ contains all of its limit points.  Alternatively, you can show that $\mathbb{R} \setminus \{c\}$ is open by showing that, for any $x \in \mathbb{R} \setminus \{c\}$, there exists an open ball of some nonzero radius centered at $x$ that does not contain $c$.
