{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e \u003c/p\u003e\r\n\u003ctable class\u003d\"problems\" style\u003d\"width: 100%;\" border\u003d\"0\"\u003e\r\n\u003ctbody\u003e\r\n\u003ctr class\u003d\"navigation\"\u003e\r\n\u003ctd width\u003d\"50%\"\u003e\u003ca href\u003d\"https://www.spoj.com/problems/CARDSHUF/en/\"\u003eEnglish\u003c/a\u003e\u003c/td\u003e\r\n\u003ctd width\u003d\"50%\"\u003e\u003ca href\u003d\"https://www.spoj.com/problems/CARDSHUF/vn/\"\u003eTiếng Việt\u003c/a\u003e\u003c/td\u003e\r\n\u003c/tr\u003e\r\n\u003c/tbody\u003e\r\n\u003c/table\u003e\r\n\u003cp\u003e\u003c/p\u003e\r\n\u003cp\u003e\"Phú ông\" has a card deck consits of n cards. He writes on each card a number from 1 to n from the top to the bottom of the deck. \u003cbr\u003e Then he does shuffle the card deck several times, each time is described by \u003cstrong\u003eS(i, j)\u003c/strong\u003e meaning: pull out the i\u003csup\u003eth\u003c/sup\u003e card then put it on the j\u003csup\u003eth\u003c/sup\u003e of the remaining cards (1 ≤ i, j ≤ n). If j \u003d n, the i\u003csup\u003eth\u003c/sup\u003e card will be the bottom card of the new one. \u003cbr\u003e For example (\u003cstrong\u003en\u003d6\u003c/strong\u003e): \u003cbr\u003e \u003cimg src\u003d\"CDN_BASE_URL/ae2e02527a8a73f850c413e2034397a6?v\u003d1714869018\" alt\u003d\"\"\u003e \u003cbr\u003e Afer x times of shuffing, \"Phú ông\" gives \"Bờm\" the card deck and chanllenges him to make it into the original order. Please help \"Bờm\"!\u003c/p\u003e\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003e- The first line contains two integer n, x. \u003cbr\u003e - Next x line(s), the p\u003csup\u003eth\u003c/sup\u003e line contains two integer i\u003csub\u003ep\u003c/sub\u003e, j\u003csub\u003ep\u003c/sub\u003e describing the p\u003csup\u003eth\u003c/sup\u003e time of shuffing (\u003cstrong\u003eS(i\u003csub\u003ep\u003c/sub\u003e, j\u003csub\u003ep\u003c/sub\u003e)\u003c/strong\u003e).\u003c/p\u003e\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003e- A single integer means the minimal number of times of shuffing the card deck to help \"Bờm\".\u003c/p\u003e\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6 4\n2 3\n1 2\n4 5\n1 6\n\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\u003ch3\u003eLimitations\u003c/h3\u003e\r\n\u003cp\u003e- 1 ≤ n, x ≤ 10\u003csup\u003e5\u003c/sup\u003e.\u003c/p\u003e\r\n\u003cp\u003e\u003c/p\u003e\n\u003c/div\u003e"}}]}