public static void main(String[]  args){
	try{
		BufferedReader in=null;
		if(args.length>0){
			in = new BufferedReader(new FileReader(args[0]));
		}
		else{
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		//			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> input = new ArrayList<String>();
		String inp = in.readLine();
		while(inp!=null){
			input.add(inp);
			inp=in.readLine();
		}
		int[][] nabomatrise = new int[input.size()][input.size()];
		for(int i=0; i<nabomatrise.length;i++){
			for(int j=0; j<nabomatrise.length;j++){
				nabomatrise[i][j]=INF;
			}	 
		}
		StringTokenizer st;
		StringTokenizer st2;
		for(int i=0;i<input.size();i++){
			st = new StringTokenizer((String)input.get(i));
			while(st.hasMoreTokens()){
				st2 = new StringTokenizer(st.nextToken(), ":");
				nabomatrise[i][Integer.parseInt(st2.nextToken())]=Integer.parseInt(st2.nextToken());
			}
		}
		System.out.println(mst(nabomatrise));
	}
	catch(Exception e){
		e.printStackTrace();
	}
}