{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows:\r\u003cbr\u003e\u003cimg src\u003d\"CDN_BASE_URL/0d5deb25e2ea0b1642fa83f2faa00196?v\u003d1726099982\"\u003e\r\u003cbr\u003eThis record defines a permutation P as follows: P(1) \u003d 4, P(2) \u003d 1, P(3) \u003d 5, etc.\r\u003cbr\u003eWhat is the value of the expression P(P(1))? It’s clear, that P(P(1)) \u003d P(4) \u003d 2. And P(P(3)) \u003d P(5) \u003d 3. One can easily see that if P(n) is a permutation then P(P(n)) is a permutation as well. In our example (believe us)\r\u003cbr\u003e\u003cimg src\u003d\"CDN_BASE_URL/4fc0a068bf10aea0e1df17d54a73ca00?v\u003d1726099982\"\u003e \r\u003cbr\u003eIt is natural to denote this permutation by P2(n) \u003d P(P(n)). In a general form the defenition is as follows: P(n) \u003d P1(n), Pk(n) \u003d P(Pk-1(n)). Among the permutations there is a very important one — that moves nothing:\r\u003cbr\u003e\u003cimg src\u003d\"CDN_BASE_URL/e8c8e8a29b2666d807da5a4d718a0e0e?v\u003d1726099982\"\u003e\r\u003cbr\u003eIt is clear that for every k the following relation is satisfied: (EN)k \u003d EN. The following less trivial statement is correct (we won\u0027t prove it here, you may prove it yourself incidentally): Let P(n) be some permutation of an N elements set. Then there exists a natural number k, that Pk \u003d EN. The least natural k such that Pk \u003d EN is called an order of the permutation P. \r\u003cbr\u003eThe problem that your program should solve is formulated now in a very simple manner: \"Given a permutation find its order.\""}},{"title":"Input","value":{"format":"HTML","content":"In the first line of the standard input an only natural number N (1 \u0026lt;\u003d N \u0026lt;\u003d 1000) is contained, that is a number of elements in the set that is rearranged by this permutation. In the second line there are N natural numbers of the range from 1 up to N, separated by a space, that define a permutation — the numbers P(1), P(2),…, P(N)."}},{"title":"Output","value":{"format":"HTML","content":"You should write an only natural number to the standard output, that is an order of the permutation. You may consider that an answer shouldn\u0027t exceed 10\u003csup\u003e9\u003c/sup\u003e."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\u003e5\r\n4 1 5 2 3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}