AOJ 0011

#include <iostream>
#include <vector>
using namespace std;
 
struct line {
  int begin;
  int end;
};
 
int main(){
  int w=0,n=0;
  int b,e;
  char comma;
  cin >> w >> n;
  vector<line> hlines;
  int answers[31];
 
  for (int i=0; i<n; i++) {
    cin >> b >> comma >> e;
    line yoko = {b,e};
    hlines.push_back(yoko);
  }
  for (int i=1; i<=w; i++) {
    int pos = i;
    for (int j=0; j<n; j++) {
      line yoko = hlines[j];
      if (yoko.begin == pos) {
        pos = yoko.end;
      } else if (yoko.end == pos) {
        pos = yoko.begin;
      }
    }
    answers[pos] = i;
  }
  for (int i=1; i<=w; i++) {
    cout << answers[i] << endl;
  }
  return 0;
}