Anything else you do, every hire, every contract, every charity donation must be justifiable in this context - unless you enjoy shareholder lawsuits.
There is a great deal of caselaw dealing with this (you can google "shareholder primacy" if you want to jump in) but it is anything but clear cut.
If the duty of directors to shareholders was as absolute as many people on the Internet think it is, companies would have to shut down and go into liquidation every time their market cap dropped below book value. But they don't (even, in some cases, when some investors might prefer it) because directors have the prerogative to seek long term gains at the expense of short term ones.
(They also have the prerogative to do the opposite, and the market unfortunately tends to reward it, but there are many exceptions.)
I believe the only thing legal you are required to do is not to defraud your shareholders. Any idiot can, legally, run a company into the ground.
Not make stuff, not employ people, not even turn a profit - just increase the share price / pay dividends