using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int lineCount = int.Parse(Reader.ReadLine()); int inputCount = int.Parse(Reader.ReadLine()); Dictionary dic = new Dictionary(); List numList = new List(); int ans = lineCount; for (int i = 1; i <= lineCount; i++) { numList.Add(i-1); } List amidaList = new List(); for (int i = 0; i < inputCount; i++) { int[] inpt = Reader.GetInt(); AmidaLine al = new AmidaLine(inpt[0]-1, inpt[1]-1, i); amidaList.Add(al); } for (int i = 0; i < lineCount; i++) { int pos = -1; int idx = i; for (int j = 0; j < inputCount; j++) { List select = new List(amidaList.FindAll(a => (a.Line1 == idx || a.Line2 == idx) && a.Pos > pos).OrderBy(b => b.Pos)); if (select.Count == 0) { break; } pos = select[0].Pos; idx = select[0].Goto(idx); } dic.Add(i, idx); } for (int i = 0; i < int.MaxValue; i++) { int[] conv = new int[lineCount]; for (int j = 0; j < numList.Count; j++) { conv[dic[j]] = numList[j]; } numList.Clear(); numList.AddRange(conv); if (numList[amidaList[0].Line1] == amidaList[0].Line1) { bool isMatch = true; for (int j = 0; j < numList.Count; j++) { if (j != numList[j]) { isMatch = false; break; } } if (isMatch) { ans = i + 1; break; } } } Console.WriteLine(ans); } public class AmidaLine { public int Line1; public int Line2; public int Pos; public int Goto(int from) { if (from == Line1) { return Line2; } return Line1; } public AmidaLine(int l1, int l2, int p) { this.Line2 = l2; this.Line1 = l1; this.Pos = p; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 4 6 1 2 2 3 3 4 3 4 2 3 1 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }