Your system is currently represented by two coordinates, $x$ and $y$. Without any constraints, any point $(x,y)$ on the plane could be a valid state of your system. But you have a constraint: valid states must obey the equation $x+\cos y=5$. This restricts the space of valid states for your system from a two-dimensional plane to a one-dimensional curve, specifically this curve:

Since your state space is constrained to be one-dimensional, you now only need one parameter to distinguish between different states. This parameter is your one degree of freedom. For example, you might choose to express the state of the system as solely a function of the single parameter $w$, where:
$$y=w$$
$$x=5-\cos w$$