Problem: Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iemitsu. Developed. Many tourists from all over the country visit every year because historic sites and remnants of old days still remain throughout the city.

This year, "Shinsengumi!" Is being broadcast in the NHK Taiga drama, so the number of tourists is increasing significantly as a place related to the Shinsengumi (* 1). Therefore, the city decided to install lanterns at intervals of 100 m along the streets connecting the historic sites scattered throughout the city. The condition is that you can reach all the historic sites in the city by following the streets decorated with lanterns, but you do not have to follow it with a single stroke. However, due to the limited budget, it is necessary to minimize the number of lanterns to be installed.

Create a program that reads the data on the street connecting the historic sites and outputs the minimum number of lanterns required. However, the distance between historic sites is greater than or equal to 200 m and is given in multiples of 100. The distance from each historic site to the nearest lantern is 100 m, and there are less than 100 historic sites in the city. There is no need to install a lantern on the historic site itself.

<image>


(* 1) The Shinsengumi was established in the form of the Aizu clan's entrustment, participated in the Aizu Boshin War known for the tragedy of Byakkotai, and Toshizo Hijikata built the grave of Isami Kondo at Tenningji Temple in the city.



Input

Given multiple datasets. Each dataset is given in the following format:


n
m
a1, b1, d1
a2, b2, d2
::
am, bm, dm


The first line of each dataset is given the number of historic sites n. It is then given a few meters of streets connecting the historic sites. The following m lines are given the three comma-separated numbers ai, bi, and di. ai and bi are historic site numbers. Historic sites are numbered from 0 to n-1. ai bi indicates that there is a street connecting them, and di represents the distance of the road between ai bi.

When n is 0, it is the last input. The number of datasets does not exceed 20.

Output

For each dataset, output the minimum number of lanterns required on one line.

Example

Input

4
4
0,1,1500
0,2,2000
1,2,600
1,3,500
0


Output

23

Solution (in CPP):

Solution:
#include<iostream>
#include<cstdio>
#include<algorithm>

#define MAX_V 100
#define INF 9999

int prim(void);

int cost[MAX_V][MAX_V]; //cost[u][v]は辺e=(u,v)のコスト(存在しない場合はINF)
int mincost[MAX_V]; //集合Xからの最小コスト
bool used[MAX_V]; //頂点iがxに含まれているか
int V; //頂点数

using namespace std;

int main(){
  int n,i,c,j,a,b;
  
  while(1){
    scanf("%d",&V);
    if(V==0) break;
    scanf("%d",&n);
    for(j=0;j<V;j++){
      for(i=0;i<V;++i){
	cost[j][i]=INF;
      }
    }
    for(i=0;i<n;i++){
      scanf("%d,%d,%d",&a,&b,&c);
      cost[a][b]=c/100-1;
      cost[b][a]=c/100-1;
    }
    printf("%d\n",prim());
    
  }
  return 0;
}

int prim(){
  
  //初期化
  for(int i=0;i<V;++i){
    mincost[i]=INF;
    used[i]=false;
  }
  
  mincost[0]=0;
  int res=0;
  
  while(true){
    int v=-1;
    //xに属さない頂点のうちxからの辺のコストが最小になる頂点を探す
    for(int u=0;u<V;u++){
      if(!used[u]&&(v==-1||mincost[u]<mincost[v])) v=u;
    }
    if(v==-1) break;
    
    used[v]=true; //頂点vをxに追加
    res+=mincost[v]; //辺のコストを比べる
    
    for(int u=0;u<V;u++){
      mincost[u]=min(mincost[u],cost[v][u]);
    }
  }
  return res;
}