#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
#define INF 2000000000
#define N 10005
#define sz(b) (int)(b.size())
#define pb push_back
int visit[N],d[N],n,m;
typedef pair<int,int> p;
vector<int>a[N],w[N],c[N];
priority_queue<p,vector<p>,greater<p> >q;
void make()
{
    int from,to,d,v;
    for(int i=1;i<=n;i++)
    {
        c[i].clear();
        a[i].clear();
        w[i].clear();
    }
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d%d",&from,&to,&d,&v);
        a[from].pb(to);
        a[to].pb(from);
        w[from].pb(d);
        w[to].pb(d);
        c[from].pb(v);
        c[to].pb(v);
    }
}
void dijkstra()
{
    for(int i=1;i<=n;i++) d[i]=(i==1?0:INF);
    memset(visit,0,sizeof(visit));
    q.push(make_pair(d[1],1));
    while(!q.empty())
    {
        p u=q.top();
        q.pop();
        int x=u.second;
        if(visit[x]) continue;
        visit[x]=1;
        for(int i=0;i<sz(a[x]);i++)
        {
            int y=a[x][i];
            if(d[y]>d[x]+w[x][i])
            {
                d[y]=d[x]+w[x][i];
                q.push(make_pair(d[y],y));
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0) break;
        make();
        dijkstra();
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            int minv=INF,ok=0;
            for(int j=0;j<sz(a[i]);j++)
            {
                if(d[a[i][j]]-d[i]<0&&abs(d[a[i][j]]-d[i])==w[i][j]) {ok=1;minv=min(c[i][j],minv);}
            }
            if(ok==1) ans+=minv;
        }
        printf("%d\n",ans);
    }
    return 0;
}