As you said, that's the literal meaning of the sentence. Actually, the sentence is a proverb. It means "When we have a good chance (accidently), we deal with the important thing first." In ancient times, 떡 was special food which couldn't get easily. 제사 was the most important rite in a year. When koreans had 제사, they had some difficulty in preparing food for 제사. Here 떡 stands for 'a precious chance,' 제사 refers to 'very important thing.'