infinitive and gerund confusion

Sometime, I cannot understand whether gerund or infinitive will be the right form of a verb in a sentence.

For example:

The key to being (or to be) healthy lies in being physically active


The first step to being …lies in being physically active

pls suggest

I suggest ‘being’. ‘To’ is a preposition there, not the infinitive particle.

Could you please explain sir…We do say the first step to reduce pollution…so why not here be…please help me

You can usually say either, but the gerund is more careful.