
def get_path(current, goal, edges, path)
  next_edges = edges.select{ |e| e[0,2].include?(current) }
  next_nodes = next_edges.map{ |e| e[0,2].select{|x| x!=current}.first }


  next_nodes.map do |n|
    if n == goal
      path + [n]
    elsif path.include?(n)
      nil
    else
      get_path(n, goal, edges, path + [n])
    end
  end
end

def cost_of_paths(start, goal, edges, edges_cost)
  paths = []
  i = 0

  get_path(start, goal, edges, [start]).flatten.each do |x|
    if x.nil?
      i += 1
      next
    elsif x == goal
      paths[i] << x
      i += 1
    elsif paths[i].nil?
      paths[i] = [x]
    else
      paths[i] << x
    end
  end

  a = paths.compact.map do |path|
    cost = 0
    path.each.with_index do |x,i|
      cost += edges_cost[[path[i], path[i+1]]] unless i == path.size-1
    end
    cost
  end
  a.min
end

n = gets.to_i
m = gets.to_i

edges = []
edges_cost = {}

m.times do
  a, b, c, d = gets.chomp.split(',').map(&:to_i)
  edges << [a, b, c, d]
  edges_cost[[a,b]] = c
  edges_cost[[b,a]] = d
end

start, goal, money, tree_cost = gets.chomp.split(',').map(&:to_i)

total_cost = cost_of_paths(start, goal, edges, edges_cost) + cost_of_paths(goal, start, edges, edges_cost) + tree_cost

p money - total_cost