Working branch-bound algorithm for finding optimial MJ matrix