Migraine and exercise have a somewhat…complicated relationship. That’s because there’s really no one-size-fits-all approach: Some workouts can improve symptoms and help mitigate certain triggers, like an inability to sleep well. Others might actually cause a throbbing head and nausea.

Roughly 30% of people with migraine may have an exercise-triggered attack at some point, and that causes a lot of folks—understandably, because who likes pain?—to stop that sport or activity because of it. If this is you, it’s still worth trying to find the right kind of fitness routine because there’s a potential mountain of good things that could happen if you can get it right. Exercise releases endorphins, hormones that are often considered the body’s natural painkillers, Moises Dominguez, MD, a neurologist at Weill Cornell Medicine, tells SELF. Plus it can lead to better sleep and positive feelings that may lower stress, anxiety, and depression in people with this chronic neurological condition. “Exercise is part of the holistic approach to managing migraine,” Dr. Dominguez says. Here’s how to get all of the great stuff and none of the bad, according to experts.

1. Take a slow and steady approach.

With migraine, it’s important not to just dive right into exercise. “The key is knowing when to say when,” Marty Fontenot, DPT, a board-certified orthopedic clinical specialist and associate professor of physical therapy at Mary Baldwin University in Staunton, Virginia, tells SELF. When you go full-force into a workout—particularly high-intensity aerobic activities like running or indoor cycling—your body uses more oxygen and loses water quickly, which could potentially cause issues.

2. Log how you feel along the way.

One way to figure out what works best for you? Start a log. “I always recommend that my patients keep track of the specific exercises that were associated with the onset of a migraine attack,” Dr. Dominguez explains. For example, if you know that more than 30 minutes of movement tends to lead to head pain, trade longer in-person classes for at-home streaming sessions you can control. If specific moves, like, say, burpees or heavy squats, cause issues, note that so you can avoid them (or tweak the way you go about it). Also, don’t forget to note other migraine triggers—say, blaring music or terrible lighting situations, like pulsing strobes and flickering fluorescent bulbs. (Another case for sweating it out at home, where you can control these types of things.)

Because everyone—and their triggers—are different, Dr. Dominguez says it’s also a good idea to write down or record other things that happen before or after your workout—like if you had a crappy night’s sleep, didn’t get a chance to eat lunch, or had a stressful day of work that made you want to go to the gym in the first place—so you can start to see patterns and hopefully better understand what’s happening and why.

3. Strategically pick your exercises.

A 2022 meta-analysis of nearly 1200 people with migraine found that strength training was a good choice when it came to improving symptoms, and aerobic exercise was another wise option. The key, however, is to keep things light: Increase your effort bit by bit, and slow things down (or peel off weight) the second you start to feel iffy, Dr. Dominguez says.

Additionally, workouts that put you in a more meditative space, like yoga (which wasn’t included in the above study) might also help. That’s because it helps combat stress, which is a major migraine trigger. Some research has shown that both yoga and medication combined can be more effective than using drugs alone. Another small study of women found that tai chi can potentially cut back on attack frequency.