lines = $stdin.read

array = lines.split("\n")

n = array[0].split(" ")[0].to_i
q = array[0].split(" ")[1].to_i

it = -1
id = Array.new(n){it+=1}
sn = Array.new(id)

for i in 1..q
  com = array[i].split(" ")[0]
  x   = array[i].split(" ")[1].to_i
  y   = array[i].split(" ")[2].to_i

  if com == '0'
    updating = if id[x] > id[y]
                 id[x]
               else
                 id[y]
               end
    updated = unless id[x] > id[y]
                id[x]
              else
                id[y]
              end

    id.collect! { |element|
      (element == updated) ? updating : element
    }
  else
    #puts "same #{x} #{y}"
    puts id[x] == id[y] ? "1" : "0"
    #puts ""
  end
end