solve joseph problem