#include <iostream>
#include <unordered_set>
#include <string>
#include <sstream>

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

int main()
{
	int n;
	std::cin >> n;
	std::unordered_set<std::string> db;
	std::string name;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			std::cout << "OK" << std::endl;
			db.insert(name);
		}
		else
		{
			int i = 1;
			while (db.find(name + patch::to_string(i)) != db.end())
			{
				i++;
			}
			std::cout << name + patch::to_string(i) << std::endl;
			db.insert(name + patch::to_string(i));
		}
	}
}


#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

	int n;
	std::cin >> n;
	std::map<std::string, int> db;
	std::string name;
	std::vector<std::string> results;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			results.push_back("OK");
			db[name] = 0;
		}
		else
		{
		    db[name]++;
			results.push_back(name + itoa(db[name]));
		}
	}

	for (int i = 0; i < n; i++)
	{
	    std::cout << results[i] << std::endl;
	}
}


#include <iostream>
#include <map>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
	int n;
	std::cin >> n;
	std::map<std::string, int> db;
	std::string name;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			std::cout << "OK" << std::endl;
			db[name] = 0;
		}
		else
		{
		    db[name]++;
			std::cout << name + itoa(db[name]) << std::endl;
		}
	}
}


#include <iostream>
#include <unordered_set>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::unordered_set<std::string> db;
	std::string name;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			std::cout << "OK" << std::endl;
			db.insert(name);
		}
		else
		{
			int i = 1;
			while (db.find(name + itoa(i)) != db.end())
			{
				i++;
			}
			std::cout << name + itoa(i) << std::endl;
			db.insert(name + itoa(i));
		}
	}
}


#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

	int n;
	std::cin >> n;
	std::map<std::string, int> db;
	std::string name;
	std::vector<std::string> results;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			results.push_back("OK");
			db[name] = 0;
		}
		else
		{
			int i = 1;
			while (db.find(name + itoa(i)) != db.end())
			{
				i++;
			}
			results.push_back(name + itoa(i));
			db[name + itoa(i)] = 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
	    std::cout << results[i] << std::endl;
	}
}


#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

	int n;
	std::cin >> n;
	std::unordered_map<std::string, int> db;
	std::string name;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			std::cout << "OK" << std::endl;
			db[name] = 0;
		}
		else
		{
		    db[name]++;
			std::cout << name + itoa(db[name]) << std::endl;
		}
	}
}


n = int(input())
db = set()
results = []
for i in range(n):
    name = input()
    if name not in db:
        db.add(name)
        results.append("OK")
    else:
        i = 1
        while name + str(i) in db:
            i += 1
        db.add(name + str(i))
        results.append(name + str(i))
print("\n".join(results))


#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

std::string itoa(int n)
{
    std::string res = "";
    while (n)
    {
        res += (n % 10) + int('0');
        n /= 10;
    }
    std::reverse(res.begin(), res.end());
    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

	int n;
	std::cin >> n;
	std::map<std::string, int> db;
	std::string name;
	std::vector<std::string> results;
	for (int i = 0; i < n; i++)
	{
		std::cin >> name;
		if (db.find(name) == db.end())
		{
			results.push_back("OK");
			db[name] = 0;
		}
		else
		{
			int i = 1;
			while (db.find(name + itoa(i)) != db.end())
			{
				i++;
			}
			results.push_back(name + itoa(i));
			db[name]++;
		}
	}

	for (int i = 0; i < n; i++)
	{
	    std::cout << results[i] << std::endl;
	}
}


#include <iostream>
using namespace std;
 int n,k;
 int has[10000000],has1[10000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
                int te=(int)ch[0];
                if (te>109){
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o));
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
                }
                else
                {
                     for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o));
                 o=o+1;
             }
             has1[sum]++;
            cout <<a[i]<<has1[sum]<<"\n";
                }
            }

        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o))-((int)ch[i]);
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=((int)ch[i])+(o*o);
                 o=o+1;
             }

             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=2;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=((int)ch[i])*o;
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=1;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o))-((int)ch[i]);
                 o=o+1;
             }
             cout <<sum;
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>

using namespace std;
 int n,k;
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int s=1;
int main()
{

    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {cout <<a[i]<<s<<"\n";
            s++;}
        k++;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,k,ok;
    cin >> n;
    string neam[n],temp[n];

     for (int i=0;i<n;i++)
        cin >>neam[i];
 for (int i=0;i<n;i++)
    {ok=0;k=0;
        for (int j=0;j<i;j++)
        {
            if (neam[i]==neam[j])
                {k++;
                ok=1;}
        }
        if (ok==0)
                {
                    cout <<"OK"<<"\n";
                }
        else
        {
            cout <<neam[i]<<k<<"\n";
        }
    }

       return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o));
                 o=o+1;
             }
             cout <<sum;
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=((int)ch[i])*o;
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=1;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=256;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o))-((int)ch[i]);
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=256;
    }
    return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o));
                 o=o+1;
             }
             has[sum]++;
            cout <<a[i]<<has[sum]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
using namespace std;
struct str {
string neam;
int k=0;
}str[100000];

int main()
{
    int n,k,ok;
//    struct str ;
    cin >> n;
     for (int i=0;i<n;i++)
        cin >>str[i].neam;
 for (int i=0;i<n;i++)
    {ok=0;
        for (int j=i-1;j>=0;j--)
        {
            if (str[i].neam==str[j].neam)
                {
               str[i].k=(str[j].k)+1;
                ok=1;
                break;
                }
        }
        if (ok==0)
                {
                    cout <<"OK"<<"\n";
                }
        else
        {
            cout <<str[i].neam<<str[i].k<<"\n";
        }
    }

       return 0;
}


#include <iostream>
using namespace std;
 int n,k;
 int has[1000000];
int serch (string temp,string a[])
{
    for (int i=0;i<k;i++)
        if (a[i]==temp)
        return 1;
    return 0;
}
int main()
{ int o=265;
    cin >>n;
    string a[n];
    for (int i=0;i<n;i++)
    {
        cin >>a[i];
    }
    int sum;
    string ch;
    char q;
    for (int i=0;i<n;i++)
    {
        if (serch(a[i],a)==0)
        {
            cout <<"OK"<<"\n";
        }
        else
            {
                ch=a[i];
             for (int i=0;i<ch.size();i++)
             {
                 sum=(((int)ch[i])+(o*o))-((int)ch[i]);
                 o=o+1;
             }
             cout <<sum;
             has[sum-10000]++;
            cout <<a[i]<<has[sum-10000]<<"\n";
            }
        k++;
        o=265;
    }
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n1;
    cin >> n1;
    map<string,int> mapa;
    vector<string> vec;
    ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0; i<n1; i++){
        string x;
        cin >> x;
        if(mapa.count(x)==0){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }
}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n2;
    cin >> n2;
    map<string,int> mapa;
    vector<string> vec;
    ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0; i<n2; i++){
        string x;
        cin >> x;
        if(mapa.count(x)==0){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
            cout << vec[i] << endl;
    }
}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
typedef set<string> sts;
int main(){
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                os << x << i;
                if(mapa.count(os.str())==0){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        cout << vec[i] << endl;
    }

}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
using namespace std;
typedef unordered_set<string> sts;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                os << x << i;
                if(mapa.count(os.str())==0){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        cout << vec[i] << endl;
    }

}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n2;
    cin >> n2;
    map<string,int> mapa;
    vector<string> vec;
    //ios::sync_with_stdio(false);
	//cin.tie(0);
	for(int i=0; i<n2; i++){
        string x;
        cin >> x;
        if(mapa.count(x)==0){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
            cout << vec[i] << endl;
    }
}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
typedef set<string> sts;
string insertar( string x, sts mapa){
     ostringstream os;
     int i=1;
     while(true){
        os << x << i;
        if(mapa.count(os.str())==0){
            mapa.insert(os.str());
            return os.str();
            break;
        }
        os.clear();
        i++;
    }
}
int main(){
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            string s=insertar(x,mapa);
            vec.push_back(s);
        }
    }
    for(int i=0; i<vec.size(); i++){
        cout << vec[i] << endl;
    }

}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string,int> mapa;
    vector<string> vec;
    ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0; i<n; i++){
        string x;
        cin >> x;
        map<string,int>::const_iterator it1;
        it1=mapa.find(x);
        if(it1 == mapa.end()){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }
}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
using namespace std;
typedef unordered_set<string> sts;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                os << x << i;
                if(mapa.count(os.str())==0){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }

}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
using namespace std;
typedef unordered_set<string> sts;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        sts::const_iterator it1;
        it1=mapa.find(x);
        if(it1 == mapa.end()){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                sts::const_iterator it;
                os << x << i;
                it=mapa.find(os.str());
                if(it==mapa.end()){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }

}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n2;
    cin >> n2;
    map<string,int> mapa;
    vector<string> vec;
    ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0; i<n2; i++){
        string x;
        cin >> x;
        if(mapa.count(x)==0){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }
}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n2;
    cin >> n2;
    map<string,int> mapa;
    vector<string> vec;
	for(int i=0; i<n2; i++){
        string x;
        cin >> x;
        if(mapa.count(x)==0){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
            cout << vec[i] << endl;
    }
}


#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int n1;
    cin >> n1;
    map<string,int> mapa;
    vector<string> vec;
    ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0; i<n1; i++){
        string x;
        cin >> x;
        map<string,int>::const_iterator it1;
        it1=mapa.find(x);
        if(it1 == mapa.end()){
            mapa.insert(make_pair(x,0));
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            mapa[x]++;
            os << x << mapa[x];
            vec.push_back(os.str());
            os.str("");
        }

	}
	for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << "\n";
        }
    }
}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
typedef set<string> sts;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                os << x << i;
                if(mapa.count(os.str())==0){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        cout << vec[i] << endl;
    }

}


#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
using namespace std;
typedef unordered_set<string> sts;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >>n;
    sts mapa;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        string x;
        cin>> x;
        if(mapa.count(x)==0){
            mapa.insert(x);
            vec.push_back("OK");
        }
        else{
            ostringstream os;
            int i=1;
            while(true){
                os << x << i;
                if(mapa.count(os.str())==0){
                    mapa.insert(os.str());
                    vec.push_back(os.str());
                    os.str("");
                    break;
                }
                os.str("");
                i++;
            }
        }
    }
    for(int i=0; i<vec.size(); i++){
        if(vec[i]!=""){
            cout << vec[i] << endl;
        }
    }

}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bits/stdc++.h>
using namespace std;

int main(){
	int t,n,m,i,j=0,s=0;
	cin>>t;
	map<string,int> mp;
	while(t--){
		string str,str2;
		cin>>str;
		if(mp[str]==0) {mp[str]=1; cout<<"OK"<<endl;}
		else{
			mp[str]++;
			str+=(char)(mp[str]+47);
			cout<<str<<endl;
		}
	}
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bits/stdc++.h>
using namespace std;

int main(){
	int t,n,m,i,j=0,s=0;
	cin>>t;
	map<string,int> mp;
	while(t--){
		string str,str2;
		cin>>str;
		if(mp[str]==0) {mp[str]=9999; cout<<"OK"<<endl;}
		else{
			mp[str]++;
			s=mp[str]-1;
			if(s>9999)str+=(char)(s%100000/10000+48);
			if(s>999)str+=(char)(s%10000/1000+48);
			if(s>99)str+=(char)(s%1000/100+48);
			if(s>9)str+=(char)(s%100/10+48);
			str+=(char)(s%10+48);
			cout<<str<<endl;
		}
	}
}


// Просто решаю.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//KiruxaLight
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>
#include <stack>
#include <deque>
#include <queue>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int INF = 1e9 + 123, MAXN = 2e5 + 47, MEGAINF = 1e18;
int p = 41;
template <class T>
istream& operator >> (istream& in, vector <T>& a)
{
    for (auto& i : a)
        in >> i;
    return in;
}
template <class T>
ostream& operator << (ostream& out, vector <T>& a)
{
    for (auto& i : a)
        out << i << " ";
    return out;
}
template <class T, class U>
istream& operator >> (istream& in, vector <pair <T, U>>& a)
{
    for (auto& i : a)
        in >> i.first >> i.second;
    return in;
}
template <class T, class U>
ostream& operator << (ostream& out, vector <pair <T, U>>& a)
{
    for (auto& i : a)
        out << i.first << " " << i.second << endl;
    return out;
}
struct node
{
    int l, r, mn, mx, add, val;
    node()
    {
        l = r = -1;
        mn = INF;
        mx = -INF;
        add = 0;
        val = 0;
    }
};
const int KEK = 3e5;
node t[KEK * 4];
void push(int v)
{
    if (t[v].add != 0)
    {
        if (t[v].l == t[v].r)
        {
            if (t[v].val == 0)
                t[v].val = t[v].add;
        }
        else
        {
            t[v * 2].add = t[v].add;
            t[v * 2 + 1].add = t[v].add;
        }
        t[v].add = 0;
    }
}
void build(int l = 0, int r = KEK - 1, int v = 1)
{
    if (l > r)
        return;
    t[v].l = l;
    t[v].r = r;
    if (l == r)
        return;
    else
    {
        int mid = l + r >> 1;
        build(l, mid, v * 2);
        build(mid + 1, r, v * 2 + 1);
    }
}
void update(int l, int r, int value, int v = 1)
{
    push(v);
    if (t[v].r < l || t[v].l > r)
        return;
    if (t[v].l >= l && t[v].r <= r)
    {
        t[v].add = value;
        push(v);
        return;
    }
    update(l, r, value, v * 2);
    update(l, r, value, v * 2 + 1);
}
int get(int pos, int v = 1)
{
    push(v);
    if (t[v].l == t[v].r)
        return t[v].val;
    int mid = t[v].l + t[v].r >> 1;
    if (pos <= mid)
        return get(pos, v * 2);
    else return get(pos, v * 2 + 1);
}
signed main()
{
    setlocale(LC_ALL, "rus");

    /*freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m;
    cin >> n >> m;
    build();
    for (int i = 0; i < m; ++i)
    {
        int l, r, x;
        cin >> l >> r >> x;
        --l, --r, --x;
        update(l, x - 1, x + 1);
        update(x + 1, r, x + 1);
        /*cout << endl;
        for (int j = 0; j < n; ++j)
            cout << get(j) << " ";
        cout << endl;*/
    }

    for (int i = 0; i < n; ++i)
        cout << get(i) << " ";
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"

// Советы по началу работы
//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
//   2. В окне Team Explorer можно подключиться к системе управления версиями.
//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
//   4. В окне "Список ошибок" можно просматривать ошибки.
//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.


// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        unordered_set<int> eras;
        for (; it != alive.end(); it++) {
            int cur = *it;
            if (cur > r) {
                break;
            }
            if (cur != v) {
                ans[cur] = v + 1;
                eras.insert(cur);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


#pragma GCC optimize("O3")
// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        unordered_set<int> eras;
        for (; it != alive.end(); it++) {
            int cur = *it;
            if (cur > r) {
                break;
            }
            if (cur != v) {
                ans[cur] = v + 1;
                eras.insert(cur);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        vector<int> eras;
        for (; it != alive.end(); it++) {
            if (*it == v) {
                continue;
            } else if (*it <= r) {
                ans[*it] = v + 1;
                eras.pb(*it);
            } else {
                break;
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        unordered_set<int> eras;
        for (; it != alive.end(); it++) {
            if (*it > r) {
                break;
            }
            if (*it != v) {
                ans[*it] = v + 1;
                eras.insert(*it);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        vector<int> eras;
        for (; it != alive.end(); it++) {
            if (*it > r) {
                break;
            }
            if (*it != v) {
                ans[*it] = v + 1;
                eras.pb(*it);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


#pragma GCC optimize("O3")
// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

inline void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = alive.lower_bound(l);
        vector<int> eras;
        for (; it != alive.end(); it++) {
            int cur = *it;
            if (cur > r) {
                break;
            }
            if (cur != v) {
                ans[cur] = v + 1;
                eras.pb(cur);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<int> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        for (it = it; it != alive.end(); it++) {
            if (*it == v) {
                continue;
            } else if (*it <= r) {
                ans[*it] = v + 1;
                alive.erase(it);
            } else {
                break;
            }
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


#pragma GCC optimize("O3")
// @author PraveenKumarRana

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

#define pb push_back
#define ll long long int
#define IOS std::ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define f(i, a, n) for (int i = a; i < n; i++)
#define fr(i, n, a) for (int i = n - 1; i >= a; --i)
#define NL "\n"

const int mod = 1e9 + 7;
const int inf = 1e16 + 7;

void SOLVE() {
    // Write your code here ?
    int n, m;
    cin >> n >> m;
    set<int> alive;
    f(i, 0, n) { alive.insert(i); }

    vector<ll> ans(n);

    while (m--) {
        int l, r, v;
        cin >> l >> r >> v;
        l--, r--, v--;

        set<int>::iterator it = lower_bound(all(alive), l);
        vector<int> eras;
        for (; it != alive.end(); it++) {
            int cur = *it;
            if (cur > r) {
                break;
            }
            if (cur != v) {
                ans[cur] = v + 1;
                eras.pb(cur);
            }
        }

        for (auto c : eras) {
            alive.erase(c);
        }
    }

    f(i, 0, n) { cout << ans[i] << " "; }
    cout << NL;
}

int main() {
    IOS;
    SOLVE();
    return 0;
}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(n)        for(int i=0;i<(int)n;i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

template <typename T>
istream & operator >> (istream &in,vector<T> &x)
{
	for(auto &x1:x)
	  in>>x1;
}

template <typename T>
ostream & operator << (ostream &out, vector<T> &x)
{
   for(auto x1:x)
   out<<x1<<" ";

   out<<'\n';
}

int main(){

int n,m; cin>>n>>m;
 set<int> alive;
    for (int i = 1; i <= N; ++i) alive.insert(i);
    alive.insert(N + 10);

    vector<int> ans(N + 1);
    rep (i, M) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);

      auto ite = alive.lower_bound(l);
      while (*ite <= r) {
        if (*ite == x) {
          ++ite;
        } else {
          ans[*ite] = x;
          alive.erase(ite++);
        }
      }
    }

    for (int i = 1; i <= N; ++i) printf("%d%c", ans[i], i == N ? '\n' : ' ');
  }
 return 0;}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

template <typename T>
istream & operator >> (istream &in,vector<T> &x)
{
	for(auto &x1:x)
	  in>>x1;
}

template <typename T>
ostream & operator << (ostream &out, vector<T> &x)
{
   for(auto x1:x)
   out<<x1<<" ";

   out<<'\n';
}

int main(){

int n,m; cin>>n>>m;
 set<int> alive;
    for (int i = 1; i <= N; ++i) alive.insert(i);
    alive.insert(N + 10);

    vector<int> ans(N + 1);
    rep (i, M) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);

      auto ite = alive.lower_bound(l);
      while (*ite <= r) {
        if (*ite == x) {
          ++ite;
        } else {
          ans[*ite] = x;
          alive.erase(ite++);
        }
      }
    }

    for (int i = 1; i <= N; ++i) printf("%d%c", ans[i], i == N ? '\n' : ' ');
  }
 return 0;}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(n)        for(int i=0;i<(int)n;i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
int n,m; cin>>n>>m;
si s;
for(int i=0;i<n;i++){
    s.insert(i+1);
}
s.insert(n*5);
vi ans(n+1,0);
for(int i=0; i<m ;i++){
    int l,r,x; cin>>l>>r>>x;

    auto it= s.lower_bound(l);
    while(*it<=r){
        if(*it==x){
            it++;
        }
        else{ans[*it]=x;
        s.erase(it++);

        }
    }

}
for (int i = 1; i <= n; i++) {
cout<<ans[i]<<' ';
}
 return 0;}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(n)        for(int i=0;i<(int)n;i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

template <typename T>
istream & operator >> (istream &in,vector<T> &x)
{
	for(auto &x1:x)
	  in>>x1;
}

template <typename T>
ostream & operator << (ostream &out, vector<T> &x)
{
   for(auto x1:x)
   out<<x1<<" ";

   out<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
int n,m; cin>>n>>m;
si s;
for(int i=0;i<n;i++){
    s.insert(i+1);
}
s.insert(n*5);
vi ans(n+1,0);
for(int i=0; i<m ;i++){
    int l,r,x; cin>>l>>r>>x;

    auto it= lower_bound(all(s),l);
    while(*it<=r){
        if(*it==x){
            it++;
        }
        else{ans[*it]=x;
        s.erase(it++);

        }
    }

}
for (int i = 1; i <= n; i++) {
cout<<ans[i]<<' ';
}
 return 0;}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(n)        for(int i=0;i<(int)n;i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
int n,m; cin>>n>>m;
si s;
for(int i=0;i<n;i++){
    s.insert(i+1);
}
s.insert(n*5);
vi ans(n+1,0);
for(int i=0; i<m ;i++){
    int l,r,x; cin>>l>>r>>x;

    auto it= lower_bound(all(s),l);
    while(*it<=r){
        if(*it==x){
            it++;
        }
        else{ans[*it]=x;
        s.erase(it++);

        }
    }

}
for (int i = 1; i <= n; i++) {
cout<<ans[i]<<' ';
}
 return 0;}


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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(n)        for(int i=0;i<(int)n;i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
int n,m; cin>>n>>m;
si s;
for(int i=0;i<n;i++){
    s.insert(i+1);
}
s.insert(n*5);
vi ans(n+1,0);
for(int i=0; i<m ;i++){
    int l,r,x; cin>>l>>r>>x;

    auto it= lower_bound(all(s),l);
    while(*it<=r){
        if(*it==x){
            it++;
        }
        else{ans[*it]=x;
        s.erase(it++);

        }
    }

}
for (int i = 1; i <= n; i++) {
cout<<ans[i]<<' ';
}
 return 0;}


/*
////////////////////////////////////////////////////////////////////////////////

       *          *      *     *      *   *      *     *   *
      * *        * *     * *   *      * *        *     * *
     *   *      *   *    *  *  *      *          *     *
    *******    *******   *   * *      * *        *     * *
   *       *  *       *  *     *      *   *      *     *   *

////////////////////////////////////////////////////////////////////////////////
*/

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

#pragma GCC optimize "trapv"
#define tw()          int t; cin>>t; while(t--)
#define ll            long long
#define pb            push_back
#define vi            vector<int>
#define pii           pair<int,int>
#define vpii          vector<pii>
#define mii           map<int,int>
#define si            set<int>
#define all(x)        x.begin(),x.end()
#define allcmp(x)     x.begin(),x.end(),cmp
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(a,n)     for(int i=(int)a;i<(int)n;i++)

const int MOD = 1000000007;

template <typename T>
istream & operator >> (istream &in,vector<T> &x)
{
	for(auto &x1:x)
	  in>>x1;
}

template <typename T>
ostream & operator << (ostream &out, vector<T> &x)
{
   for(auto x1:x)
   out<<x1<<" ";

   out<<'\n';
}

int main(){

int N,M; cin>>N>>M;
 set<int> alive;
    for (int i = 1; i <= N; ++i) alive.insert(i);
    alive.insert(N + 10);

    vector<int> ans(N + 1);
    rep (i, M) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);

      auto ite = alive.lower_bound(l);
      while (*ite <= r) {
        if (*ite == x) {
          ++ite;
        } else {
          ans[*ite] = x;
          alive.erase(ite++);
        }
      }
    }

    for (int i = 1; i <= N; ++i) printf("%d%c", ans[i], i == N ? '\n' : ' ');

 return 0;}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>
#include <cstring>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 3e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int st[4*N], n;

void update(int id, int ql, int qr, int l, int r, int x) {
    if (ql <= l && r <= qr) {
        st[id] = x;
        return;
    }
    if (r < ql || qr < l) return;
    update(id*2, ql, qr, l, (l+r)/2, x);
    update(id*2+1, ql, qr, (l+r)/2+1, r, x);
}

void push(int id, int l, int r) {
    if (l == r) {
        cout << st[id]+1 << " ";
    }
    else {
        if (st[id*2] == -1) st[id*2] = st[id];
        if (st[id*2+1] == -1) st[id*2+1] = st[id];
        push(id*2, l, (l+r)/2);
        push(id*2+1, (l+r)/2+1, r);
    }
}

struct Query {
    int l;
    int r;
    int x;
    Query(int l, int r, int x) : l(l), r(r), x(x) {}
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    memset(st, -1, sizeof(st));
    vector<Query> queries;
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        queries.emplace_back(l, r, x);
    }
    reverse(begin(queries), end(queries));

    for (auto& q : queries) {
        update(1, q.l, q.x-1, 0, n-1, q.x);
        update(1, q.x+1, q.r, 0, n-1, q.x);
    }
    push(1, 0, n-1);
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> a(n);
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        a[l].emplace_back(i, x);
        a[r].emplace_back(i, x);
    }
    set<pair<int, int>> curr;
    for (int i = 0; i < n; ++i) {
        vector<pair<int, int>> to_remove;
        for (auto& p : a[i]) {
            if (curr.count(p)) to_remove.push_back(p);
            curr.insert(p);
        }

        auto first = curr.begin();
        auto second = ++curr.begin();
        if (first->second != i) {
            cout << first->second+1 << " ";
        } else if (second != curr.end()) {
            cout << second->second+1 << " ";
        } else {
            cout << 0 << " ";
        }

        for (auto& p : to_remove) {
            curr.erase(p);
        }
    }
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> a(n);
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        a[l].emplace_back(i, x);
        a[r].emplace_back(i, x);
    }
    set<pair<int, int>> curr;
    for (int i = 0; i < n; ++i) {
        vector<pair<int, int>> to_remove;
        for (auto& p : a[i]) {
            if (curr.count(p)) to_remove.push_back(p);
            curr.insert(p);
        }

        auto first = curr.begin();
        auto second = ++curr.begin();
        if (first->second != i) {
            cout << first->second+1 << " ";
        } else if (second != curr.end() && second->second != i) {
            cout << second->second+1 << " ";
        } else {
            cout << 0 << " ";
        }

        for (auto& p : to_remove) {
            curr.erase(p);
        }
    }
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct X {
    int time;
    int winner;
    bool is_begin;

    bool operator<(const X &rhs) const {
        return time < rhs.time;
    }
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<vector<X>> a(n);
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        if (l != x) {
            a[l].push_back({i, x, true});
            a[x - 1].push_back({i, x, false});
        }
        if (r != x) {
            a[x+1].push_back({i, x, true});
            a[r].push_back({i, x, false});
        }
    }
    set<X> curr;
    for (int i = 0; i < n; ++i) {
        for (auto& p : a[i]) {
            if (p.is_begin)
                curr.insert(p);
        }

        auto first = curr.begin();
        if (!curr.empty()) cout << first->winner+1 << " ";
        else cout << 0 << " ";

        for (auto& p : a[i]) {
            if (!p.is_begin)
                curr.erase(p);
        }
    }
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> a(n);
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        a[l].emplace_back(i, x);
        a[r].emplace_back(i, x);
    }
    set<pair<int, int>> curr;
    for (int i = 0; i < n; ++i) {
        vector<pair<int, int>> to_remove;
        for (auto& p : a[i]) {
            if (curr.count(p)) to_remove.push_back(p);
            curr.insert(p);
        }

        auto first = curr.begin();
        auto second = ++curr.begin();
        bool found = false;
        for (auto& p : curr) {
            if (p.second != i) {
                cout << p.second+1 << " ";
                found = true;
                break;
            }
        }
        if (!found) cout << 0 << " ";

        for (auto& p : to_remove) {
            curr.erase(p);
        }
    }
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>
#include <cstring>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int st[4*N], n;

void update(int id, int ql, int qr, int l, int r, int x) {
    if (ql <= l && r <= qr) {
        st[id] = x;
        return;
    }
    if (r < ql || qr < l) return;
    update(id*2, ql, qr, l, (l+r)/2, x);
    update(id*2+1, ql, qr, (l+r)/2+1, r, x);
}

void push(int id, int l, int r) {
    if (l == r) {
        cout << st[id]+1 << " ";
    }
    else {
        if (st[id*2] == -1) st[id*2] = st[id];
        if (st[id*2+1] == -1) st[id*2+1] = st[id];
        push(id*2, l, (l+r)/2);
        push(id*2+1, (l+r)/2+1, r);
    }
}

struct Query {
    int l;
    int r;
    int x;
    Query(int l, int r, int x) : l(l), r(r), x(x) {}
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    memset(st, -1, sizeof(st));
    vector<Query> queries;
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        queries.emplace_back(l, r, x);
    }
    reverse(begin(queries), end(queries));

    for (auto& q : queries) {
        update(1, q.l, q.x-1, 0, n-1, q.x);
        update(1, q.x+1, q.r, 0, n-1, q.x);
    }
    push(1, 0, n-1);
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>
#include <cstring>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 3e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct Fight {
    int time;
    int x;
};
Fight st[4*N], n;

void update(int id, int ql, int qr, int l, int r, Fight& f) {
    if (ql <= l && r <= qr) {
        st[id] = f;
        return;
    }
    if (r < ql || qr < l) return;
    update(id*2, ql, qr, l, (l+r)/2, f);
    update(id*2+1, ql, qr, (l+r)/2+1, r, f);
}

void push(int id, int l, int r) {
    if (l == r) {
        cout << (st[id].x == inf ? 0 : st[id].x+1) << " ";
    }
    else {
        if (st[id].time < st[id*2].time) st[id*2] = st[id];
        if (st[id].time < st[id*2+1].time) st[id*2+1] = st[id];
        push(id*2, l, (l+r)/2);
        push(id*2+1, (l+r)/2+1, r);
    }
}

struct Query {
    int l;
    int r;
    Fight f;
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;
    for (auto&& x : st) x = {inf, inf};
    vector<Query> queries;
    rep (i, m) {
        int l, r, x; cin >> l >> r >> x;
        l--, r--, x--;
        queries.push_back({l, r, {i, x}});
    }
    reverse(begin(queries), end(queries));

    for (auto& q : queries) {
        update(1, q.l, q.f.x-1, 0, n-1, q.f);
        update(1, q.f.x+1, q.r, 0, n-1, q.f);
    }
    push(1, 0, n-1);
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, w;
int answer[300001];
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		alive.insert(i);

	for (int i = 0; i < m; i++) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		set<int>::iterator it = alive.lower_bound(l);
		vector<int> toErase;
		while (it != alive.end()) {
			int cur = *it;
			if (cur > r)
				break;
			if (cur != x) {
				toErase.pb(cur); answer[cur] = x;
			}
			it++;
		}

		for (size_t j = 0; j < toErase.size(); j++)
			alive.erase(toErase[j]);
	}
	FOR(i, 1, n) {
		printf("%d ", answer[i]);
	}
#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	cin >> n >> m;
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		cin >> l >> r >> w;
		auto bg = alive.lower_bound(l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d%d%d", &l, &r, &w);
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d%d%d", &l, &r, &w);
		vector <int> toEr;
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
				toEr.pb(*ed);
			}
			ed++;
		}
		FOR(i, 0, toEr.size() - 1) alive.erase(toEr[i]);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	cin >> n >> m;
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n+1);
	while (m--) {
		cin >> l >> r >> w;
		vector <int> toErase;
		auto it = lower_bound(ALL(alive),l);
		while (it != alive.end() && *it <= r) {
			if (*it != w) {
				ans[*it] = w;
				toErase.push_back(*it);
			}
			it++;
		}
		FORD(i, toErase.size() - 1, 0) {
			alive.erase(toErase[i]);
		}
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d%d%d", &l, &r, &w);
		vector <int> toEr;
		auto ed = alive.lower_bound(l);
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
				toEr.pb(*ed);
			}
			ed++;
		}
		FOR(i, 0, toEr.size() - 1) alive.erase(toEr[i]);
	}
	FOR(i, 1, n) {
		printf("%d ", ans[i]);
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	cin >> n >> m;
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d %d %d", &l, &r, &w);
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
int answer[300001];
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		alive.insert(i);

	for (int i = 0; i < m; i++) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		set<int>::iterator it = alive.lower_bound(l);
		vector<int> toErase;
		while (it != alive.end()) {
			int cur = *it;
			if (cur > r)
				break;
			if (cur != x) {
				toErase.pb(cur); answer[cur] = x;
			}
			it++;
		}

		for (size_t j = 0; j < toErase.size(); j++)
			alive.erase(toErase[j]);
	}
	FOR(i, 1, n) {
		printf("%d ", answer[i]);
	}
#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	cin >> n >> m;
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n+1);
	while (m--) {
		cin >> l >> r >> w;
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
//#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	scanf("%d%d", &n, &m);
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d%d%d", &l, &r, &w);
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FORD(i, a, b) for (int i=a; i<=b; i--)
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define DEBUG

int n, m, l, r, w;
vector <int> ans;
set <int> alive;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("E:/C++/input.txt", "r", stdin);
	freopen("E:/C++/output.txt", "w", stdout);
	auto start = chrono::steady_clock::now();
#endif

	cin >> n >> m;
	FOR(i, 1, n) {
		alive.insert(i);
	}
	ans.resize(n + 1);
	while (m--) {
		scanf("%d %d %d", &l, &r, &w);
		auto bg = lower_bound(alive.begin(), alive.end(), l);
		auto ed = bg;
		while (ed != alive.end() && *ed <= r) {
			if (*ed != w) {
				ans[*ed] = w;
			}
			ed++;
		}
		alive.erase(bg, ed);
		alive.insert(w);
	}
	FOR(i, 1, n) {
		cout << ans[i] << ' ';
	}

#ifdef DEBUG
	auto end = chrono::steady_clock::now();
	chrono::duration<double> diff = end - start;
	cout << endl << "Time: " << diff.count() << " s\n";
	return 0;

#endif

	return 0;
}


#include <iostream>

using namespace std;
int tree[300005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft  && r <= Qright)
    {
        if(l != r)tree[node] = val;
        else{
            if(l != x3 && tree[node] == 0)tree[node] = val;
            return;
        }
    }
           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);

    }

void query(int node, int l, int r)
{
    if(l == r){
        cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}
int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

   query(1,1,n);

}


#include <iostream>

using namespace std;
int tree[3000005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft  && r <= Qright)
    {
        if(l != r)tree[node] = val;
        else{
            if(l != x3 && tree[node] == 0)tree[node] = val;
            return;
        }
    }
           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);

    }

void query(int node, int l, int r)
{
    if(l == r){
        cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}
int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

   query(1,1,n);

}


#include <iostream>

using namespace std;
int tree[2000005];
int ans[200005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

     if(l == r && l != x3){
        tree[node] = val;
        ans[l] = val;
     }

           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);

    }

void query(int node, int l, int r)
{
     if(tree[2*node] == 0)tree[2*node] = tree[node];
      if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];

    if(l == r){
        if(l == tree[1])cout << 0 << " ";
        else cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}

int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

   for(int i=1 ; i<n ; i++){
    cout << ans[i];
   }

}


#include <iostream>

using namespace std;
int tree[3000005];
int ans[300005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

     if(l == r && l != x3){
        tree[node] = val;
        ans[l] = val;
     }

           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);

    }

void query(int node, int l, int r)
{
     if(tree[2*node] == 0)tree[2*node] = tree[node];
      if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];

    if(l == r){
        if(l == tree[1])cout << 0 << " ";
        else cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}

int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

   for(int i=1 ; i<n ; i++){
    cout << ans[i];
   }

}


#include <iostream>

using namespace std;
int dsu[300005];
int main()
{
   int n,m;
   cin >> n >> m;
   for(int i=0 ; i<m ; i++){
    int x1,x2,x3;
    cin >> x1 >> x2 >> x3;
    for(int i= x1 ; i <= x2 ; i++){
        if(i != x3 && dsu[i] == 0)dsu[i] = x3;
    }
   }

   for(int i=1 ; i<= n ; i++)cout << dsu[i] << " ";
    return 0;
}


#include <iostream>

using namespace std;
const int N = 3e5+2;
int tree[4*N];
int arr[N];

void solve(int val,int l,int r)
{
   for(l;l<=r;l++)
    if(l!=val && arr[l]==0)
        arr[l] = val;
}

void update(int node,int l,int r ,int Qleft, int Qright , int val)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft && r <= Qright){
        if(tree[node] == 0){
        tree[node] = val;
        solve(val,l,r);
        }else{
         if(arr[tree[node]] == 0 )arr[tree[node]] = val;
        }
        return;
    }
           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val);
            update(2*node+1, mid+1, r,Qleft,Qright, val);

    }

void query(int node, int l, int r)
{
     if(tree[2*node] == 0)tree[2*node] = tree[node];
      if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];

    if(l == r){
        if(l == tree[1])cout << 0 << " ";
        else cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}

int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3);
    }

   for(int i=1 ; i<=n ; i++){
   cout << arr[i] << " ";
   }

}


#include <iostream>

using namespace std;
int tree[3000005];
bool v[300005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft  && r <= Qright)
    {
        if(v[node] == true){
            if(tree[2*node] == 0)tree[2*node] = tree[node];
            if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];
        }
        if ( l != r && v[node] == true){
        tree[node] = val;
        v[node] = true;
        return;
        }else if(l == r ){
          if(l != x3){
            tree[node] = val;
            v[node] = true;
            return;
          }else{
             return;
          }
        }

    }

           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);
            v[node] = true;

    }

void query(int node, int l, int r)
{
     if(tree[2*node] == 0)tree[2*node] = tree[node];
      if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];

    if(l == r){
        if(l == tree[1])cout << 0 << " ";
        else cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}

int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

   query(1,1,n);

}


#include <iostream>

using namespace std;
int tree[300005];

void update(int node,int l,int r ,int Qleft, int Qright , int val,int x3)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft  && r <= Qright)
    {
        if(l != r)tree[node] = val;
        else{
            if(l != x3 && tree[node] == 0)tree[node] = val;
            return;
        }
    }
           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val,x3);
            update(2*node+1, mid+1, r,Qleft,Qright, val,x3);

    }

int query(int node, int l, int r, int idx)
{
    if(l > idx || r < idx )return 0;
    if(idx >= l && idx <= r && tree[node] != 0)
    {
        return tree[node];
    }

    int mid = (l + r) / 2;
    int p1 = query(2*node, l, mid, idx);
    int p2 = query(2*node+1, mid+1, r, idx);
    return p1 + p2;
}
int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3,x3);
    }

    for(int i=0 ; i<n ; i++){
        cout << tree[n+i] << " ";
    }

}


#include <iostream>

using namespace std;
const int N = 3e5+2;
int tree[4*N];
int arr[N];

void solve(int val,int l,int r)
{
   for(l;l<=r;l++)
    if(l!=val && arr[l]==0)
        arr[l] = val;
}

void update(int node,int l,int r ,int Qleft, int Qright , int val)
{
    if(l > Qright || r < Qleft )return;

    if(l >= Qleft && r <= Qright){
        if(tree[node] == 0){
        tree[node] = val;
        solve(val,l,r);
        }else{
         if(tree[node] != val){
            if(arr[tree[node]] == 0 )
                arr[tree[node]] = val;
         }
        }
        return;
    }
           int mid = (l + r) / 2;
            update(2*node, l, mid, Qleft,Qright, val);
            update(2*node+1, mid+1, r,Qleft,Qright, val);

    }

void query(int node, int l, int r)
{
     if(tree[2*node] == 0)tree[2*node] = tree[node];
      if(tree[2*node+1] == 0)tree[2*node+1] = tree[node];

    if(l == r){
        if(l == tree[1])cout << 0 << " ";
        else cout << tree[node] << " ";
        return;
    }

    int mid = (l + r) / 2;
    query(2*node, l, mid);
    query(2*node+1, mid+1, r);
}

int main()
{
    int n,m;
    cin >> n>>m;
    for(int i=0 ; i<m ; i++){
        int x1,x2,x3;
        cin >> x1 >> x2 >> x3;
        update(1,1,n,x1,x2,x3);
    }

   for(int i=1 ; i<=n ; i++){
   cout << arr[i] << " ";
   }

}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int)3e5 + 9;
using namespace std;

int arr[MAXN];
int par[MAXN];

int find_set(int v){
    if(v == par[v])
        return v;
    return par[v] = find_set(par[v]);
}

int main(){

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < MAXN; i++)
        par[i] = i;

    while(m--) {

        int x, y, z;
        cin >> x >> y >> z;

        int cur = find_set(x);

        while(cur <= y) {

            if(cur == z){
                ++cur;
                cur = find_set(cur);
                continue;
            }

            if(!arr[cur]) arr[cur] = z;
            par[cur] = cur + 1;
            cur = find_set(cur);
        }
    }

    for(int i = 1; i <= n; i++){
        cout<< arr[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int)3e5 + 9;
using namespace std;

int arr[MAXN];
int par[MAXN];

int find_set(int v){
    if(v == par[v])
        return v;
    return par[v] = find_set(par[v]);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < MAXN; i++)
        par[i] = i;

    while(m--) {

        int x, y, z;
        cin >> x >> y >> z;

        int cur = find_set(x);

        while(cur <= y) {

            if(cur == z){
                ++cur;
                cur = find_set(cur);
                continue;
            }

            if(!arr[cur]) arr[cur] = z;
            par[cur] = cur + 1;
            cur = find_set(cur);
        }
    }

    for(int i = 1; i <= n; i++){
        cout<< arr[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int) 3e5+5;
using namespace std;

int parent[MAXN];
void make_set(int v){
    parent[v]=v;
}

int find_set(int v){
    if(parent[v]==v){
        return v;
    }else{
        return find_set(parent[v]);
    }
}

void v1beatsv2(int v1, int v2){
    v1 = find_set(v1);
    v2 = find_set(v2);
    if( v1 != v2 && parent[v2]==v2){
        parent[v2] = v1;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    int x, y, z;
    for(int i = 1; i <= n; i++){
        make_set(i);
    }
    for(int i = 0; i < m; i++){
        cin>>x>>y>>z;
        for(int j = x; j <= y; j++){
            if(parent[j]!=j) continue;
            v1beatsv2(z,j);
        }
        if(i==m-1){
            parent[z]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        cout<<parent[i]<<" ";
    }
}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int) 3e5+5;
using namespace std;

int parent[MAXN];
void make_set(int v){
    parent[v]=v;
}

int find_set(int v){
    if(parent[v]==v){
        return v;
    }else{
        return parent[v] = find_set(parent[v]);
    }
}

void v1beatsv2(int v1, int v2){
    v1 = find_set(v1);
    v2 = find_set(v2);
    if( v1 != v2 && parent[v2]==v2){
        parent[v2] = v1;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    int x, y, z;
    for(int i = 1; i <= n; i++){
        make_set(i);
    }
    for(int i = 0; i < m; i++){
        cin>>x>>y>>z;
        if(parent[x])
        for(int j = x; j <= y; j++){
            if(parent[j]!=j) continue;
            v1beatsv2(z,j);
        }
        if(i==m-1){
            parent[z]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        cout<<parent[i]<<" ";
    }
}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int) 3e5+5;
using namespace std;

int parent[MAXN];
void make_set(int v){
    parent[v]=v;
}

int find_set(int v){
    if(parent[v]==v){
        return v;
    }else{
        return find_set(parent[v]);
    }
}

void v1beatsv2(int v1, int v2){
    v1 = find_set(v1);
    v2 = find_set(v2);
    if( v1 != v2 && parent[v2]==v2){
        parent[v2] = v1;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    int x, y, z;
    for(int i = 1; i <= n; i++){
        make_set(i);
    }
    for(int i = 0; i < m; i++){
        cin>>x>>y>>z;
        for(int j = x; j <= y; j++){
            v1beatsv2(z,j);
        }
        if(i==m-1){
            parent[z]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        cout<<parent[i]<<" ";
    }
}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int) 3e5+5;
using namespace std;

int arr[MAXN];
int tree[4*MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    int n;
    cin>>n;

}


#include <bits/stdc++.h>
#define endl '\n'

const int INF = (int) 1e9;
const int long minINF = (int) -1e9;
const int mod = (int) 1e9+7;

const int MAXN = (int) 3e5+5;
using namespace std;
int arr[MAXN];
int parent[MAXN];
void make_set(int v){
    parent[v]=v;
}

int find_set(int v){
    if(parent[v]==v){
        return v;
    }else{
        return parent[v] = find_set(parent[v]);
    }
}

void v1beatsv2(int v1, int v2){
    v1 = find_set(v1);
    v2 = find_set(v2);
    if(parent[v2]==v2)
        arr[v2] = v1;
    if( v1 != v2){
        parent[v2] = v1;

    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    int x, y, z;
    for(int i = 1; i <= n; i++){
        make_set(i);
    }
    for(int i = 0; i < m; i++){
        cin>>x>>y>>z;
        x = find_set(x);
        y = find_set(y);
        for(int j = x; j <= y; j++){
            j = find_set(j);
            v1beatsv2(z,j);
        }
        if(i==m-1){
            arr[z]=0;
        }
    }
    for(int i = 1; i <= n; i++){
        cout<<arr[i]<<" ";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;

int answer[300005]={0};
int ar[300005];

int find_par(int i)
{
   if(i==ar[i])return i;
    return ar[i]=find_par(ar[i]);
}

int main() {
    faf;
    int n, m;
    cin >> n >> m;
    int i;
    int l,r,x;
    int j;
    for(i=0;i<=n+1;i++)ar[i]=i;
    for (i = 0; i < m; i++){
        cin>>l>>r>>x;

        for(j=find_par(l);j<=r;j=find_par(j))
        {
             answer[j]=x;
             ar[j]=j+1;
        }
        answer[x]=0;
        ar[x]=x;
    }

    for(i=1;i<=n;i++)
    {
        cout<<answer[i]<<" ";
    }

}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.tie(nullptr)
using namespace std;

int answer[300005]={0};
int ar[300005];

int find_par(int i)
{
   if(i==ar[i])return i;
    return ar[i]=find_par(ar[i]);
}

int main() {
    faf;
    int n, m;
    cin >> n >> m;
    int i;
    int l,r,x;
    int j;
    for(i=0;i<=n+1;i++)ar[i]=i;
    for (i = 0; i < m; i++){
        cin>>l>>r>>x;

        for(j=find_par(l);j<=r;j=find_par(j))
        {
             answer[j]=x;
             ar[j]=j+1;
        }
        answer[x]=0;
        ar[x]=x;
    }

    for(i=1;i<=n;i++)
    {
        cout<<answer[i]<<" ";
    }

}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.tie(nullptr)
using namespace std;

int answer[300005]={0};
int ar[300005];

int find_par(int i)
{
    while(i!=ar[i])
    {
        ar[i]=ar[ar[i]];
        i=ar[i];
    }
    return i;
}

int main() {
    faf;
    int n, m;
    cin >> n >> m;
    int i;
    int l,r,x;
    int j;
    for(i=0;i<=n+1;i++)ar[i]=i;
    for (i = 0; i < m; i++){
        cin>>l>>r>>x;

        for(j=find_par(l);j<=r;j=find_par(j))
        {
             answer[j]=x;
             ar[j]=j+1;
        }
        answer[x]=0;
        ar[x]=x;
    }

    for(i=1;i<=n;i++)
    {
        cout<<answer[i]<<" ";
    }

}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;

int answer[300005]={0};
int ar[300005];

int find_par(int i)
{
    if(i==ar[i])
    {
        return i;
    }
    return ar[i]=find_par(ar[i]);
}

int main() {
    int n, m;
    cin >> n >> m;
    int i;
    int l,r,x;
    int j;
    for(i=0;i<=n+1;i++)ar[i]=i;
    for (i = 0; i < m; i++){
        cin>>l>>r>>x;

        for(j=find_par(l);j<=r;j=find_par(j))
        {
             answer[j]=x;
             ar[j]=j+1;
        }
        answer[x]=0;
        ar[x]=x;
    }

    for(i=1;i<=n;i++)
    {
        cout<<answer[i]<<" ";
    }

}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
using namespace std;

int answer[300005]={0};
int ar[300005];

int find_par(int i)
{
    if(i==ar[i])
    {
        return i;
    }
    return ar[i]=find_par(ar[i]);
}

int main() {
    int n, m;
    cin >> n >> m;
    int i;
    int l,r,x;
    int j;
    for(i=0;i<=n+1;i++)ar[i]=i;
    for (i = 0; i < m; i++){
        cin>>l>>r>>x;

        for(j=find_par(l);j<=r;j=find_par(j))
        {
             answer[j]=x;
             ar[j]=j+1;
        }
        answer[x]=0;
        ar[x]=x;
    }

    for(i=1;i<=n;i++)
    {
        cout<<answer[i]<<" ";
    }

}


#include <bits/stdc++.h>
#define ll long long
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;

int ar[300000+1]={0};

int main()
{
    faf;
    int n,m;
    cin>>n>>m;
    int i;
    int l,r,x;int j;
    for(i=0;i<m;i++)
    {
        cin>>l>>r>>x;
        for(j=l;j<=r;j++)
        {
            if(ar[j]==0||ar[j]==j)ar[j]=x;
        }
    }
    ar[x]=0;
    for(i=1;i<=n;i++)cout<<ar[i]<<" ";

}