N = gets.to_i
h = {}
m = 0
a = (N-1).times.map {
  a,b = gets.split.map &:to_i
  x = h[a]||={}
  y = h[b]||={}
  c = 1
  c += 1  while x[c]
  c += 1  while y[c]
  x[c] = y[c] = 0
  m = c  if m < c
  c
}
p m
a.each {|i| p i}