I won't help too much but I'll say this.
Imagine,
st = extend empty "a" 5
st2 = extend st "b" 3
st2 then becomes something like this:
extend extend empty "a" 5 "b" 3
I hope that can push you towards the solution a bit.
Another way you can think about it is this:
Since the extend function returns a State which is actually a function of String -> Int, you can use that to your advantage and backtrack through the chain of extends.
I hope I didn't spoil too much :)