import java.io.*;
import java.util.*;

class Main{
		public static void main(String args[]) throws IOException{
			ArrayList<String> line_list = new ArrayList<String>();

			Scanner scan = new Scanner(System.in);
			
			int low,line;
			
			low = Integer.parseInt(scan.next());
			line = Integer.parseInt(scan.next());
			
			for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			}			
			
			int now,priority,list_n,list_a,list_p;
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			for(int i=0;i<low;i++){
				res.add(0);
			}
			
			for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			}
			
			for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			}
			
	}
} import java.io.*; io.* java import java.util.*; util.* java class Main{
		public static void main(String args[]) throws IOException{
			ArrayList<String> line_list = new ArrayList<String>();

			Scanner scan = new Scanner(System.in);
			
			int low,line;
			
			low = Integer.parseInt(scan.next());
			line = Integer.parseInt(scan.next());
			
			for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			}			
			
			int now,priority,list_n,list_a,list_p;
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			for(int i=0;i<low;i++){
				res.add(0);
			}
			
			for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			}
			
			for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			}
			
	}
} Main public static void main(String args[]) throws IOException{
			ArrayList<String> line_list = new ArrayList<String>();

			Scanner scan = new Scanner(System.in);
			
			int low,line;
			
			low = Integer.parseInt(scan.next());
			line = Integer.parseInt(scan.next());
			
			for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			}			
			
			int now,priority,list_n,list_a,list_p;
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			for(int i=0;i<low;i++){
				res.add(0);
			}
			
			for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			}
			
			for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			}
			
	} main {
			ArrayList<String> line_list = new ArrayList<String>();

			Scanner scan = new Scanner(System.in);
			
			int low,line;
			
			low = Integer.parseInt(scan.next());
			line = Integer.parseInt(scan.next());
			
			for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			}			
			
			int now,priority,list_n,list_a,list_p;
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			for(int i=0;i<low;i++){
				res.add(0);
			}
			
			for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			}
			
			for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			}
			
	} ArrayList<String> line_list = new ArrayList<String>(); line_list new ArrayList<String>() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int low low line; line low = Integer.parseInt(scan.next()) low Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan line = Integer.parseInt(scan.next()) line Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			} int i=0; int i=0; i 0 i<line i line i++ i++ i {
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			} {
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			} String str1 = scan.next(); str1 scan.next() scan.next scan String str2 = ","+String.valueOf(i); str2 ","+String.valueOf(i) "," String.valueOf(i) String.valueOf String i str1 = str1+str2 str1 str1+str2 str1 str2 line_list.add(str1) line_list.add line_list str1 int now now priority priority list_n list_n list_a list_a list_p; list_p ArrayList<Integer> res = new ArrayList<Integer>(); res new ArrayList<Integer>() for(int i=0;i<low;i++){
				res.add(0);
			} int i=0; int i=0; i 0 i<low i low i++ i++ i {
				res.add(0);
			} {
				res.add(0);
			} res.add(0) res.add res 0 for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			} int i=1; int i=1; i 1 i<=low i low i++ i++ i {
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			} {
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			} priority = -1 priority -1 1 now = i now i for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				} int j=0; int j=0; j 0 j<line_list.size() j line_list.size() line_list.size line_list j++ j++ j {
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				} {
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				} String[] strAry = line_list.get(j).split(","); strAry line_list.get(j).split(",") line_list.get(j).split line_list.get(j) line_list.get line_list j "," list_n = Integer.parseInt(strAry[0]) list_n Integer.parseInt(strAry[0]) Integer.parseInt Integer strAry[0] strAry 0 list_a = Integer.parseInt(strAry[1]) list_a Integer.parseInt(strAry[1]) Integer.parseInt Integer strAry[1] strAry 1 list_p = Integer.parseInt(strAry[2]) list_p Integer.parseInt(strAry[2]) Integer.parseInt Integer strAry[2] strAry 2 if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					} now == list_n && priority < list_p now == list_n now list_n priority < list_p priority list_p {
						now = list_a;
						priority = list_p;
						j = 0;
					} now = list_a now list_a priority = list_p priority list_p j = 0 j 0 if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;} now == list_a && priority < list_p now == list_a now list_a priority < list_p priority list_p {
						now = list_n;
						priority = list_p;
						j = 0;
					} now = list_n now list_n priority = list_p priority list_p j = 0 j 0 if(priority == (line - 1)){break;} priority == (line - 1) priority (line - 1) line 1 {break;} break; res.set(now-1,i) res.set res now-1 now 1 i for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			} int i=0; int i=0; i 0 i<res.size() i res.size() res.size res i++ i++ i {
					System.out.println(res.get(i));
			} {
					System.out.println(res.get(i));
			} System.out.println(res.get(i)) System.out.println System.out System System.out res.get(i) res.get res i String args[] args
import java.io.*;
import java.util.*;

class Main{
		public static void main(String args[]) throws IOException{
			ArrayList<String> line_list = new ArrayList<String>();

			Scanner scan = new Scanner(System.in);
			
			int low,line;
			
			low = Integer.parseInt(scan.next());
			line = Integer.parseInt(scan.next());
			
			for(int i=0;i<line;i++){
				String str1 = scan.next();
				String str2 = ","+String.valueOf(i);
				str1 = str1+str2;
				line_list.add(str1);
			}			
			
			int now,priority,list_n,list_a,list_p;
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			for(int i=0;i<low;i++){
				res.add(0);
			}
			
			for(int i=1;i<=low;i++){
				priority = -1;
				now = i;
				for(int j=0;j<line_list.size();j++){
					String[] strAry = line_list.get(j).split(",");
					list_n = Integer.parseInt(strAry[0]);
					list_a = Integer.parseInt(strAry[1]);
					list_p = Integer.parseInt(strAry[2]);
					if(now == list_n && priority < list_p){
						now = list_a;
						priority = list_p;
						j = 0;
					}
					if(now == list_a && priority < list_p){
						now = list_n;
						priority = list_p;
						j = 0;
					}
					else if(priority == (line - 1)){break;}
				}
				res.set(now-1,i);
			}
			
			for(int i=0;i<res.size();i++){
					System.out.println(res.get(i));
			}
			
	}
}