Cookie finder

You have m * n grid with cookies and obstacles on it.
Find a position that is closest to all cookies but not on obstacles