#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin >>n>>m;
    vector<vector<int>> lst; //y x x2
    for(int i = 0; i<m;i++){
        int x,y,x2,y2;
        cin >>x>>y>>x2>>y2;

        lst.push_back({y,x,x2});
        
    }
    sort(lst.begin(),lst.end(), greater<>());

    map<int,int> mapa;
    for (int i = 0; i<m;i++){
        vector<vector<int>> a;
        if(mapa.count(lst[i][2])){
            //mapa[lst[i][1]] = mapa[lst[i][2]];
            a.push_back({lst[i][1], mapa[lst[i][2]]});
        }else {
            a.push_back({lst[i][1] , lst[i][2]} );
            //mapa[lst[i][1]] = lst[i][2];
        }if(mapa.count(lst[i][1])){
            a.push_back({lst[i][2], mapa[lst[i][1]]});
            //mapa[lst[i][2]] = mapa[lst[i][1]];
        }else {
            a.push_back({lst[i][2], lst[i][1]});
            //mapa[lst[i][2]] = lst[i][1];
        }
        for(int i = 0;i < a.size();i++){
            mapa[a[i][0]] =a[i][1];
        }
    }
    for(int i = 1; i<n+1;i++){
        if(mapa.count(i)) cout << mapa[i]<<'\n';
        else cout << i<<'\n';
    }
}