Anselm wanted to prove the existence of God, so he proposed the ontological argument. The ontological argument is deductive, and uses a priori reasoning. This means that it starts with a statement that is known to be true solely through definition (God is the greatest conceivable being) and develops the implications of this statement in order to reach a reasonable conclusion. The deductive reasoning allows him to simply showing what the definition means. Hence, Anselm states that God exists in the mind, even the mind of those who deny His existence.
However he points out that it is greater to exist in reality and in the mind than in the mind alone. Take for example; a pile of notes worth £1000. If it exists in the mind it is merely a pleasant thought, however, if it exists in reality it can be spent and is greater. Since God is the greatest conceivable being, He must exist in reality and in the mind, because to think otherwise involves contradiction of the theory, which you agree with.
Anselm also says that God could possibly be a contingent God, who is dependent on something else for existence. If this was true God would not be worthy of worship and would not be the greatest conceivable being. A necessary God, one whose non existence is impossible, is greater than a contingent God whose non existence is possible. God has no creator, so to have to have someone else to depend on for existence, means they are not God. Therefore, we must accept that god is also necessary, as well as existant in reality, because to think otherwise involves a contradiction. The reason for people being able to deny the existence of God is due to them knowing the definition of the word God, not the existence of God.