solve using k-map