#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int stringTOlint(string s) {
	//string→lint
	lint Z = s.size();
	lint ret = 0;
	reverse(s);
	rep(i, Z) {
		ret += ((s[i] - '0') * pow(10, i));
	}
	return ret;
}

int main() {
	lint W, N;
	cin >> W >> N;
	vector<string>S(N);
	rep(i, N) {
		cin >> S[i];
	}
	bool flag = false;
	vector<string>A(N);
	vector<string>B(N);
	rep(i, N) {
		flag = false;
		rep(j, S[i].size()) {
			if (S[i][j] == ',') {
				flag = true;
			}
			else {
				if (flag) {
					B[i].push_back(S[i][j]);
				}
				else {
					A[i].push_back(S[i][j]);
				}
			}
		}
	}
	vector<lint>IA(N);
	vector<lint>IB(N);
	rep(i, N) {
		IA[i] = stringTOlint(A[i]);
		IB[i] = stringTOlint(B[i]);
	}
	lint now = 0;
	vector<lint>ANS;
	for (int i = 1; i <= W; i++) {
		now = i;
		rep(j, N) {
			if (IA[j] == now) {
				now = IB[j];
			}
			else if (IB[j] == now) {
				now = IA[j];
			}
		}
		ANS.push_back(now);
	}
	vector<IP>P(W);
	rep(i, W) {
		P[i].first = ANS[i];
		P[i].second = i + 1;
	}
	sort(P);
	rep(i, W) {
		cout << P[i].second << endl;
	}
}
