goal seek in a formula

because the goal seek tool only allows you to enter a value in the second box 'to value' and not reference a value already in a cell it makes it hard for large volumes of entries.

how would i go about writing a formula that would cover this:

set: M5 (formula in M5 = O5-N5-F5)
To value: G5 (no formula in cell, just value)
By changing cell: O5

Thanks,