import Data.IntMap ((!))
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Maybe
import Control.Applicative

untilFix f x = if f x == x then x else untilFix f (f x)

main = do
 [n,q] <- map read . words <$> getLine
 cxys <- map ((\[c,x,y]->(c,(x,y))) . map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
 mapM_ print (uft n q cxys)

uft :: Int -> Int -> [(Int,(Int,Int))] -> [Int]
uft n q = reverse . fst . foldl' process ([],(M.fromDistinctAscList (zip [0..n-1] [0..])))

process (lg,m) (c,(x,y))
 | c==0 = (lg, M.insert (untilFix (m!) (max x y)) (untilFix (m!) (min x y)) m)
 | c==1 = ((if v1==v2 then 1 else 0) : lg, m)
 where
  v1 = untilFix (m!) (min x y)
  v2 = untilFix (m!) (max x y)