You already know that eating plants can yield optimal health, better mental and brain health included. Even if you don’t go fully vegan or plant-based, eating a Mediterranean diet (which allows a small amount of fish or other lean animal protein) has been linked with slower rates of cognitive decline and may even help prevent Alzheimer’s and dementia.

But there's a catch: If you’re mixing that healthy plant-based diet with even a small amount of high-animal-fat or unhealthy foods (like cheating with cheeseburgers) on a regular basis, you could be negating much of those health benefits in the first place, the latest research shows.

The science behind brain health and your mostly healthy diet

In a study published in the journal Alzheimer’s & Dementiawhich involved 5,001 older adults who completed questionnaires every three years from 1993 to 2012, researchers looked at how closely participants not only followed a Mediterranean diet but also often added in unhealthy foods, such as the high-saturated fat foods that are hallmarks of a standard American diet. Participants regularly filled out questionnaires about their diet choices including the number of times they indulged in unhealthy items–and took basic cognitive tests. While typical foods in a Mediterranean diet include vegetables, fruits, legumes, fish, olive oil, potatoes, unrefined grains, and wine (at moderate levels), foods categorized as “unhealthy” include refined grains, fried foods, sweets, red and processed meat, pizza and full-fat dairy, like ice cream.

As you might expect, those who stuck the most closely to the Mediterranean diet–and had the lowest intake of high-fat, high-sugar foods–experienced a slower cognitive decline throughout the years of the study. “People were having some of the unhealthy foods, but not that frequently,” says Puja Agarwal, Ph.D., lead study author, and nutritional epidemiologist and assistant professor in the department of internal medicine at Rush Medical College in Chicago. From a cognition standpoint, the healthier dieters had the cognitive power equal to someone nearly 6 years younger in age versus those who didn’t adhere as well to a mostly plant-based or Mediterranean diet or had allowed themselves more high-fat foods more often.

Those individuals who ate the highest amount of unhealthy foods and didn’t adhere as well to the Mediterranean diet actually negated the potential brain health effects of plant-based foods.  “Those with a higher intake of foods like sweets, refined grains, and red and processed meats, did not have the significant cognitive benefit of eating a Mediterranean diet,” Agarwal says. So if you're going to eat plant-based for brain health, you have to stick with it.

How unhealthy foods damage the brain

Why is unhealthy food so bad for the brain?  Blame something called "advanced glycation end products" or AGEs for short. Foods like processed meats and fast foods have high levels of AGEs, and a high level of AGEs in the body can cause inflammation and oxidative stress. “As a result, normal cell functioning is affected, making cells more susceptible to damage and premature aging,” Agarwal says, adding that inflammation and oxidative stress are also an underlying mechanism for cognitive decline, including Alzheimer’s, and most other chronic diseases.

If you’re eating a plant-based or plant-only diet and want the brain benefits, limiting your consumption of processed foods and other unhealthy foods like sweets and those that are fried is critical. (Yes you can be vegan or plant-based and dive into a bowl of potato chips.) But how much of these junk foods can you safely allow in your diet before the brain benefits of eating a diet rich in plant-based food are erased?

Agarwal’s study didn’t calculate the exact number of servings of unhealthy foods that would nullify the cognitive benefits of eating plant-based, but she points to the Mediterranean-DASH Intervention for Neurogenerative Delay (MIND) diet, designed specifically to benefit brain health, for guidance. It recommends having no more than one meal a week of fast or fried food and limiting sweets and pastries to fewer than five servings a week.

Following these guidelines and keeping the focus on whole plant foods as much as possible can go a long way in protecting your brain and keeping your memory, focus, and sharpness intact. “Cognitive decline and Alzheimer’s are huge public concerns of an aging population,” Agarwal says. “Making some wise modifications to your diet may help slow cognitive decline over time.”