Problem: Dilku was thinking about the first time he met his girl... It was indeed a walk to remember. The romantic weather and her silly talks. He was completely mesmarized. Those were the days!..    

Today is his girl's birthday and he wants to make it special for her. He wants to again take her on a "special walk" that they would remember for the lifetime.    

The city in which Dilku lives is represented as an unweighted directed graph with N nodes and M edges. A "special walk" in the graph starting at node u is a simple path that begins and ends at the same node u.    

Formally, A special walk is path  u , a1 , a2 , a3 ,..., ai ,.... , u  where ai are distinct and not equal to u for all i.

Now since Dilku is really nervous about taking his girl out, he needs your help. For every node in the given graph, tell whether it is possible for Dilku to take his girl on a "special walk" starting at that node.

Input:

First line of a two space separated integers denoting N and M, the number of nodes and number of directed edges in the corresponding graph.       
Following M lines contain two space separated integers  u v  denoting a directed edge in the graph from vertex numbered u to vertex numbered v.

Output:

Print N space separated integers, where ith integer can be either 1 or 0 depicting whether it is possible to go on a special walk starting at node i or not. 

Constraints:
1 ≤ N ≤ 10^5
1 ≤ M ≤ 2 · 10^5
1 ≤ u, v ≤ N

SAMPLE INPUT
5 5
1 2 
2 3 
3 4 
4 5
4 2

SAMPLE OUTPUT
0 1 1 1 0 

Explanation

In the given graph , there is just one directed cycle :  2-->3-->4-->2. Hence, for all nodes on this cycle, the answer is yes and for others the answer is no.

Solution (in PYTHON):

Solution:
Graph = {}

N, M = map(int, raw_input().split())
for i in xrange(1, N+1):
    Graph[i] = []
for i in xrange(M):
    u, v = map(int, raw_input().split())
    Graph[u].append(v)
    
marked = set()
visit_stack = []
visit_index = {}
parent = {}

dfsPos = 1
dfsNum = {}

oReps = []
oNodes = []
components = {}
components_count = {}

def root(s):
    global dfsPos
    dfsNum[s] = dfsPos
    dfsPos+=1
    
    oReps.append(s)
    oNodes.append(s)

def backtrack(a, b):
    if b == oReps[-1]:
        oReps.pop()

        while True:
            c = oNodes.pop()
            components[c] = b
            components_count.setdefault(b, 0)
            components_count[b] += 1 
            if b == c:
                break

def traverse(a, b):
    global dfsPos
    dfsNum[b] = dfsPos
    dfsPos += 1

    oReps.append(b)
    oNodes.append(b)

def traverse_non_tree(a, b):
    if b in marked and b not in components: # b is in oNodes
        while dfsNum[b] < dfsNum[oReps[-1]]:
            oReps.pop()

for s in Graph: # all nodes in Graph
    pass
    if s not in marked:
        marked.add(s)
        root(s)
        parent[s] = s
        visit_stack.append(s)
        visit_index[s] = 0
        
        while visit_stack:
            current_node = visit_stack[-1]

            if visit_index[current_node] == len(Graph[current_node]):
                backtrack(parent[current_node], current_node)
                visit_stack.pop()

            else:
                next_node_idx = visit_index[current_node]
                next_node = Graph[current_node][next_node_idx]
                visit_index[current_node] = next_node_idx + 1

                if next_node in marked:
                    traverse_non_tree(current_node, next_node)
                else:
                    marked.add(next_node)
                    parent[next_node] = current_node
                    visit_index[next_node] = 0

                    traverse(current_node, next_node)
                    visit_stack.append(next_node)

        
simple_loop = []
for i in xrange(1, N+1):
    if components_count[components[i]] > 1:
        simple_loop.append(1)
    else:
        simple_loop.append(0)

print " ".join(map(str, simple_loop))