#include <iostream>
#include <unordered_set>
void add_friends(int pupil, const std::unordered_map<int, std::unordered_set<int>> &friendships, std::unordered_set<int>& group_friends){
if(group_friends.contains(pupil)){
return;
}
//first, add the current pupil
group_friends.insert(pupil);
//then, add this pupils friends
if(friendships.contains(pupil)){
for (const auto & pupil_friend : friendships.at(pupil)){
// group_friends.insert(pupil);
add_friends(pupil_friend, friendships, group_friends);
}
}
}
int main(){
int num_pupils, num_frendships;
std::unordered_map<int, std::unordered_set<int>> friendships{};
std::cin >> num_pupils;
std::cin >> num_frendships;
for(int i=0; i<num_frendships; i++){
int friend1, friend2;
std::cin >> friend1 >> friend2;
friendships[friend1].insert(friend2);
}
std::unordered_set<int> group1, group2;
std::unordered_set<int> group1_friends, group2_friends;
// now, we'll add the first pupil into the first group
// and then iterate over the rest and add them to the 1st one if they have no friends there
// and if no, then we add them to the second one, if they also have no friends there
// ughhhh but I know this is so no optimal fuck
for(int pupil = 1; pupil<= num_pupils; pupil++){
if(!group1_friends.contains(pupil)){
group1.insert(pupil);
add_friends(pupil, friendships, group1_friends);
}
else if(not group2_friends.contains(pupil)){
group2.insert(pupil);
add_friends(pupil, friendships, group2_friends);
} else {
std::cout << "IMPOSSIBLE";
break;
}
}
for(int i=1; i<=num_pupils; i++){
std::cout << (group1.contains(i) ? "1" : "2" ) << " ";
}
std::cout << "\n";
}