If during prayer, one thinks “I’m better than X” does it invalidate his prayer?

Or is showing off the prayer itself what invalidates it?

Prayer is valid, but when losing concentration in prayer, one loses the benefit of prayer.