import strutils, sequtils proc cin: string = while true: let tmp = readChar stdin if not isSpaceAscii tmp: safeAdd result, tmp elif tmp != '\r': break proc main = let N, M = parseInt cin() var cups = "/xxx/" cups[N] = 'o' for i in 0 ..< M: let P, Q = parseInt cin() swap(cups[P], cups[Q]) echo find(cups, 'o') main()