How the brain decides what to remember