N = gets.to_i
ABs = readlines.map{|l| l.split.map(&:to_i)}

g = ABs.each_with_object(Hash.new{|h, k| h[k] = []}){|(a, b), h| h[a] << b; h[b] << a}
h = {}
(1 .. N).each do |a|
  bs = g[a]
  cs = [*1 .. N] - bs.map{|b| h[[a, b].sort]}.compact.sort
  bs.select{|b| h[[a, b].sort].nil?}.each{|b| h[[a, b].sort] = cs.shift}
end
puts g.values.map(&:size).max
ABs.each{|a, b| puts h[[a, b].sort]}