Srimad Bhagavatam Canto 08, Chapter 02, Text 31

SB 8.2.31

ittham gajendrah sa yadapa sankatam
 pranasya dehi vivaso yadrcchaya
aparayann atma-vimoksane ciram
 dadhyav imam buddhim athabhyapadyata
 
Translation by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada: 
 
When the King of the elephants saw that he was under the clutches of the crocodile by the will of providence and, being embodied and circumstantially helpless, could not save himself from danger, he was extremely afraid of being killed. He consequently thought for a long time and finally reached the following decision.
 
Purport by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada: 
 
Everyone in the material world is engaged in a struggle for existence. Everyone tries to save himself from danger, but when one is unable to save himself, if he is pious, he then takes shelter of the lotus feet of the Supreme Personality of Godhead. This is confirmed in Bhagavad-gita (7.16):
 
catur-vidha bhajante mam
 janah sukrtino ’rjuna
arto jijñasur artharthi
 jñani ca bharatarsabha
 
Four kinds of pious men — namely, one who is in danger, one who is in need of money, one who is searching for knowledge and one who is inquisitive — begin to take shelter of the Supreme Personality of Godhead in order to be saved or to advance. The King of the elephants, in his condition of danger, decided to seek shelter of the lotus feet of the Lord. After considerable thought, he intelligently arrived at this correct decision. Such a decision is not reached by a sinful man. Therefore in Bhagavad-gita it is said that those who are pious (sukrti) can decide that in a dangerous or awkward condition one should seek shelter of the lotus feet of Krsna.
Srimad Bhagavatam Canto 08, Chapter 02, Text 30
Srimad Bhagavatam Canto 08, Chapter 02, Text 32