How to avoid the wandering of the mind

First of all you cannot stop the wandering of the mind. But you can fight to… control it and then God’s grace will grant the victory.
First, you must place at the gate of your heart strict and unsleeping guards. In fact one of the most essential things in this life is a vigilant heart. To achieve this, you need prayer and obedience.
Constantly wrestle with your thoughts, and whenever your mind wanders, bring it back to prayer. God does not require from those who are beginners under obedience prayer completely free of distractions. Do not despond when your thoughts wander, but remain calm, and unceasingly recall your mind. Unbroken recollection is proper only to an angel.

Based on St. John of the Ladder

In this photo is depicted a monk praying in front of the icon of the Mother of God at a vigil in Vatopaidi’s Katholikon.