#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define edge pair<int,int>
#define x first
#define y second

const int N=1e5+5;
int n,m,ans[N];
vector<edge> g[N];

void dfs(int x){
	for(edge e:g[x]) if(!ans[e.x]){
		ans[e.x]=ans[x]==e.y?1+(ans[x]==1):e.y;
		dfs(e.x);
	}
}

signed main(){
	read(n,m);
	for(int i=1,x,y,z;i<=m;i++){
		read(x,y,z);
		g[x].emplace_back(y,z);
		g[y].emplace_back(x,z);
	}
	ans[1]=1;
	dfs(1);
	for(int i=1;i<=n;i++) write(ans[i]),puts("");
}
#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N;
  scanf("%lld", &N);

  vector<pair<ll, string>> list;
  rep(i, N) {
    string name;
    cin >> name;
    ll h;
    scanf("%lld", &h);
    list.emplace_back(make_pair(h, name));
  }

  sort(list.begin(), list.end(), greater<pair<ll, string>>());

  cout << (list[1].second) << endl;

  // cout << ans << endl;
}
