import sys import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra input = sys.stdin.buffer.readline read = sys.stdin.buffer.read N, M = map(int, input().split()) uvcds = list(map(int, read().split())) us = uvcds[0::4] vs = uvcds[1::4] cs = uvcds[2::4] ds = uvcds[3::4] uv2i = {(min(u, v), max(u, v)): i for i, (u, v) in enumerate(zip(us, vs))} graph = csr_matrix((cs + cs, (us + vs, vs + us)), shape=(N + 1, N + 1), dtype=np.int64) dist_vec, predecessor = dijkstra(graph, directed=False, indices=1, return_predecessors=True) ans = int(np.round(dist_vec[N])) v = N while v != 1: p = predecessor[v] if p > v: p, v = v, p i = uv2i[(p, v)] cs[i] = ds[i] v = p graph = csr_matrix((cs + cs, (us + vs, vs + us)), shape=(N + 1, N + 1), dtype=np.int64) ans += int(np.round(dijkstra(graph, directed=False, indices=N)[1])) print(ans)