import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	}


} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	}


} Main public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	} main {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	} String strLine =""; strLine "" BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in)); stdReader new BufferedReader(new InputStreamReader(System.in)) int MAX_DETASET  = 100; MAX_DETASET 100 int cnt = 0; cnt 0 boolean nullflug = true; nullflug true ArrayList<Integer> lineList1 = new ArrayList<Integer>(); lineList1 new ArrayList<Integer>() ArrayList<Integer> lineList2 = new ArrayList<Integer>(); lineList2 new ArrayList<Integer>() ArrayList<Integer>	numberList = new ArrayList<Integer>(); numberList new ArrayList<Integer>() ArrayList<Integer> tateyokoList = new ArrayList<Integer>(); tateyokoList new ArrayList<Integer>() int lineMaxTate = 100; lineMaxTate 100 int lineMaxYoko = 100; lineMaxYoko 100 while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		} (strLine = stdReader.readLine()) != null (strLine = stdReader.readLine()) strLine stdReader.readLine() stdReader.readLine stdReader null {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		} String[] temp = strLine.split(",",0); temp strLine.split(",",0) strLine.split strLine "," 0 if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			} cnt > lineMaxYoko cnt lineMaxYoko {
				break;
			} break; if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			} temp.length > 1 temp.length temp temp.length 1 {//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			} lineList1.add(Integer.parseInt(temp[0])-1) lineList1.add lineList1 Integer.parseInt(temp[0])-1 Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 1 lineList2.add(Integer.parseInt(temp[1])-1) lineList2.add lineList2 Integer.parseInt(temp[1])-1 Integer.parseInt(temp[1]) Integer.parseInt Integer temp[1] temp 1 1 {

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			} if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				} cnt == 0 cnt 0 {
					lineMaxTate = Integer.parseInt(temp[0]);
				} lineMaxTate = Integer.parseInt(temp[0]) lineMaxTate Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				} cnt == 1 cnt 1 {
					lineMaxYoko = Integer.parseInt(temp[0]);

				} lineMaxYoko = Integer.parseInt(temp[0]) lineMaxYoko Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 cnt++ cnt for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		} int j = 0; int j = 0; j 0 j< lineMaxTate j lineMaxTate j++ j++ j {

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		} {

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		} int now = j; now j for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			} int i = lineMaxYoko - 1; int i = lineMaxYoko - 1; i lineMaxYoko - 1 lineMaxYoko 1 i >=0 i 0 i-- i-- i {

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			} {

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			} if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				} lineList1.get(i) == now lineList1.get(i) lineList1.get lineList1 i now {

					now = lineList2.get(i);

				} now = lineList2.get(i) now lineList2.get(i) lineList2.get lineList2 i if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				} lineList2.get(i) == now lineList2.get(i) lineList2.get lineList2 i now {

					now = lineList1.get(i);

				} now = lineList1.get(i) now lineList1.get(i) lineList1.get lineList1 i { //????????????

				} numberList.add(now) numberList.add numberList now for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		} int i = 0; int i = 0; i 0 i < numberList.size() i numberList.size() numberList.size numberList i++ i++ i {

			System.out.println(numberList.get(i)+1);

		} {

			System.out.println(numberList.get(i)+1);

		} System.out.println(numberList.get(i)+1) System.out.println System.out System System.out numberList.get(i)+1 numberList.get(i) numberList.get numberList i 1 String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	}


} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	}


} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		int MAX_DETASET  = 100;
		int cnt = 0;

		boolean nullflug = true;
		ArrayList<Integer> lineList1 = new ArrayList<Integer>();
		ArrayList<Integer> lineList2 = new ArrayList<Integer>();
		ArrayList<Integer>	numberList = new ArrayList<Integer>();
		ArrayList<Integer> tateyokoList = new ArrayList<Integer>();

		int lineMaxTate = 100;
		int lineMaxYoko = 100;

		//1. int?????????????????\???????????????????????????

		while((strLine = stdReader.readLine()) != null) {

			String[] temp = strLine.split(",",0);

			if(cnt > lineMaxYoko){
				break;
			}else if(temp.length > 1 ){//????????????????????????
				lineList1.add(Integer.parseInt(temp[0])-1);
				lineList2.add(Integer.parseInt(temp[1])-1);

			}else{

				if(cnt == 0){
					lineMaxTate = Integer.parseInt(temp[0]);
				}else if(cnt == 1){
					lineMaxYoko = Integer.parseInt(temp[0]);

				}
				cnt++;
			}

		}





		//2. ???????????????????????¨??????????????\??£?????????????????????????????§???????????????
		//   ????§??????????numberList???????´?

		for(int j = 0; j< lineMaxTate; j++){

			int now = j;

			for(int i = lineMaxYoko - 1; i >=0 ; i--){

				if(lineList1.get(i) == now){

					now = lineList2.get(i);

				}else if (lineList2.get(i) == now){

					now = lineList1.get(i);

				}else{ //????????????

				}

			}

			numberList.add(now);
		}


		//3. ??????

		for(int i = 0; i < numberList.size(); i++){

			System.out.println(numberList.get(i)+1);

		}


	}


}