N = gets.to_i

last = gets.split.map.with_index {|n,i| [n.to_i,i] }.sort[1,2]
readlines.each do |s|
  a = s.split.map.with_index {|n,i| [n.to_i,i] }.sort[1,2]
  if last.last.last == a.last.last
    last[0] = [last[0].first + a[1].first, a[1].last]
    last[1] = [last[1].first + a[0].first, a[0].last]
  else
    last[0][0] = last[1].first + a[0].first
    last[1][0] = last[1].first + a[1].first
  end
end
puts last.max.first
