Monoid where every element has a one-sided inverse is a group. 
Let $M$ be a monoid such that:
for all $x \in M$, there exists $y \in M$ such that $xy = 1$ or $yx = 1$.
Is it true that $M$ is a group?

In other words, if every element of $M$ has a one-sided inverse, then does it follow that every element of $M$ is invertible?

My thoughts
Suppose if I constrain every element to say, have a right inverse, then the statement does hold true.
Indeed, let $x \in M$ be arbitrary and $x'$ be a right inverse of $x$. We show that $x'x = 1$ as well.
First, let $x''$ denote the right inverse of $x'$. Then, we have
$$x'x = x'x(x'x'') = x'(xx')x'' = x'x'' = 1.$$
In fact, the above proof gives us a more refined result:

If $x, x', x'' \in M$ satisfy $xx' = x'x'' = 1$, then $x'$ is the inverse of $x$ (and thus, $x = x''$).
In words: If a right inverse of an element has a right inverse, then the element is invertible.

Thus, if we are looking for a counterexample, then there must necessarily be an element $x \in M$ which has a right inverse but not a left inverse. Moreover, any right inverse $x'$ of $x$ cannot have a right inverse.

Motivation/Context/Source
I didn't come across this in a textbook or anywhere else. I came up with this question because I was aware of the constrained example mentioned above and was wondering if this is true.
I don't have much background about monoids either. I am aware of some properties of finite semigroups/monoids (existence of idempotent powers, Green's relations) but those don't seem to be very fitting here. I haven't even been able to rule out that I can get a counterexample with a finite $M$.
 A: All such monoids are groups.
Take a monoid $M$, equipped with a function $m: M \rightarrow M$ so that for all $x \in M$, either $x \cdot m(x) = 1$ or $m(x) \cdot x = 1$. holds.
Since any set with associativity, left identity and left inverse is a group, it suffices to prove that every element $c \in M$ has a left inverse. More precisely, we will prove that $m(c)$ is indeed the left inverse of the element $c$.
Take some $c \in M$ such that $c \cdot m(c) = 1$. We have to prove $m(c) \cdot c = 1$. So consider the element $d = m(c) \cdot c$. By the property assumed above, we have either $m(d) \cdot d = 1$ or $d \cdot m(d) = 1$.

*

*In the first case, $m(d) \cdot d = 1$. Expanding the definition of $d$, we get that
$m(c) \cdot c = 1 \cdot m(c) \cdot c = m(d) \cdot d \cdot m(c) \cdot c = m(d) \cdot m(c) \cdot c \cdot m(c) \cdot c = m(d) \cdot m(c) \cdot c = m(d) \cdot d = 1.$
So in this case, $m(c)$ is indeed the left inverse of $c$.


*Otherwise $d \cdot m(d) = 1$. But then $m(c) \cdot c = m(c) \cdot c \cdot 1 = m(c) \cdot c \cdot d \cdot m(d) = m(c) \cdot c \cdot m(c) \cdot c \cdot m(d) = m(c) \cdot c \cdot m(d) = d \cdot m(d) = 1.$
In either case, $m(c) \cdot c = 1$, so we are done.
A: Say we have $xy=1$. We need to prove $yx=1$. First, $g := yx$ is idempotent:
$$g^2=(yx)(yx)=y(xy)x=yx=g.$$
If $g$ has a left inverse, we may multiply with it from the left and deduce $g=1$. Similarly, when $g$ has a right inverse, we may multiply with it from the right and deduce $g=1$. So we have $yx=g=1$ in either case.
