import Control.Applicative import Control.Monad import Data.Bits readInts :: IO [Int] readInts = map read . words <$> getLine rightmost :: Int -> Int rightmost n = length $ takeWhile (not . testBit n) [0..31] swap :: Int -> Int -> Int -> Int swap x n m = x `xor` a `xor` shift a d where d = m-n a = (shift x (-d) `xor` x) .&. shift 1 n main = do n <- readLn m <- readLn query <- replicateM m readInts let query' = map (map (subtract 1)) query f [] s = 1 + rightmost s f ([p,q]:rs) s = f rs (swap s p q) in print $ f query' (shift 1 (n-1))