class Node
  attr_accessor :nid, :a, :b

  def initialize(nid,a,b)
    @nid = nid
    @a = a
    @b = b
  end
end

class Graph
  def initialize(nodes)
    @nodes = nodes
  end

  def weight(x,y)
    [@nodes[x].a, @nodes[y].b].min
  end

  def calculation
    min = Float::INFINITY
    (0..@nodes.length-1).to_a.permutation(@nodes.length).to_a.each do |route|
      route.push route[0]
      r_cost = new_route(route).cost
      min = r_cost if min > r_cost
    end
    return min
  end

  def new_route(route)
    Route.new(route, self)
  end
end

class Route
  attr_accessor :nids, :cost

  def initialize(nids, graph)
    @nids = nids
    @graph = graph
    @cost = cost_calculation
  end

  def cost_calculation
    @cost = 0
    (1..nids.length-1).each do |i|
      @cost += @graph.weight(@nids[i-1],@nids[i])
    end
    @cost
  end
end

class Array
  def to_graph
    nodes = []
    self.each_with_index do |arr, i|
      arr.unshift(i)
      nodes.push Node.new(*arr)
    end
    return Graph.new(nodes)
  end
end

def main(*args)
  n = args[0].to_i
  arr = []
  n.times do |i|
    arr.push args[i+1].split(' ').map(&:to_i)
  end
  return arr.to_graph.calculation
  Blocks.new(arr).calculation % (10**9 + 7)
end

if __FILE__ == $0
  n = gets.chomp!
  arr = gets.chomp!
  print main(n,arr)
end