To open the safe in Shinra Mansion you must go through the numbers in either left or right direction before selecting. You cannot go past the numbers so be careful! You must land exactly on each number in the correct direction without going past the number.
The numbers and directions are:
Upon successfully opening the safe, you will face a boss, Lost Number. Defeating him will earn you the Item for Red XIII's Level 4 Limit Break, Cosmo Memory. You can then pick up the Odin Summon Materia as well as the Key Item 'Basement Key', which will allow you to get Vincent Valentine to join your party from the Shinra Mansion basement.