FIrst backtracking algorithm version