import Control.Monad

data Point = Point { point :: Int
                    ,trail :: Int
                    ,flag :: Bool} deriving (Eq,Show)

data Road = Road { p1 :: Int
                  ,p2 :: Int
                  ,len :: Int} deriving (Show)

minPoint :: [Point] -> Point
minPoint ps = foldl1 f ps
                where f p1 p2
                        | flag p1 = p2
                        | (not (flag p2)) && (trail p1 > trail p2) = p2
                        | otherwise = p1

allAcces :: [Road] -> [Point]-> [Point]
allAcces [] visited = visited
allAcces roads visited = allAcces roads' visited'
  where minP = minPoint visited
        roads' = deleteRoad minP roads
        visited' = used minP (acces minP roads visited)

acces :: Point -> [Road] -> [Point] -> [Point]
acces p [] visited = visited
acces p (r:rs) visited
  | point p == p1 r = acces p rs (update p r visited)
  | otherwise       = acces p rs visited

update :: Point -> Road -> [Point] -> [Point]
update p r [] = [(Point (p2 r) ((trail p) + (len r)) False)]
update p r (v:vs)
  | p2 r == point v = (Point (point v) (min (trail v) ((trail p) + (len r))) (flag v)):vs
  | otherwise       = v:(update p r vs)

used :: Point -> [Point] -> [Point]
used p [] = []
used p (x:xs)
  | point p == point x  = (Point (point p) (trail p) True):xs
  | otherwise           = x:(used p xs)

deleteRoad :: Point -> [Road] -> [Road]
deleteRoad _ [] = []
deleteRoad p (r:rs)
  | point p == p1 r = deleteRoad p rs
  | otherwise       = r:(deleteRoad p rs)

splitByC :: String -> [String] -> [String]
splitByC "" ss = ss
splitByC (',':xs) ss = splitByC xs (ss ++ [""])
splitByC (x:xs) ss = splitByC xs ((init ss) ++ [(last ss) ++ [x]])

split' :: String -> [String]
split' s = splitByC s [""]

makeRoadL :: [Road]-> [Int] -> [Road]
makeRoadL rs [] = rs
makeRoadL rs [a,b,c,d] = (Road a b c):(Road b a d):rs

minTrail :: Int -> [Point] -> Int
minTrail i (p:ps)
  | i == point p = trail p
  | otherwise    = minTrail i ps

main :: IO ()
main = do
  n <- getLine
  m <- readLn
  sss <- replicateM m getLine
  sgvp <- getLine
  let ss = map (map (read :: String -> Int)) $ map split' sss
      [s,g,v,p] = map (read :: String -> Int) $  split' sgvp
      rs = foldl makeRoadL [] ss
      go = allAcces rs [(Point s 0 False)]
      back = allAcces rs [(Point g 0 False)]
      ans = - (minTrail g go) - (minTrail s back) + v - p
  putStrLn $ show ans