first matchin algorithm ;-)