LED Scheme
InterviewTime limit3sMemory limit1024 MB
Given LEDs as directed edges between controller outputs, decide for each LED whether it can be the only one lit, meaning no other path leads from its anode to its cathode.
Problem
A light-emitting diode (LED) is an electronic component with two terminals, called the anode and the cathode. In the figure, A and K on the left are the anode and the cathode. When the anode has a higher voltage than the cathode (figure (a)), the LED lights up. When the cathode has a higher voltage than the anode (figure (b)), the LED stays off but is not damaged. The LED also stays off when the anode and the cathode have equal voltages (figures (c) and (d)).

Juku has a number of LEDs and a controller that drives them. The controller has outputs, numbered . Each output can be set by a program to a higher or a lower voltage (1 and 0 in the figures), which controls whether the LEDs connected to the controller light up.
Juku wants to connect many LEDs to his controller so that each LED can be turned on separately from all the others, that is, so that a state exists in which only that LED is lit. For example, in the scheme on the left of the figure below, both LEDs can be turned on separately. In the scheme on the right, both LEDs always light up together.

Write a program that takes a description of Juku's scheme and determines which LEDs can be turned on separately from the others with this scheme.
Input
The first line contains the number of controller outputs () and the number of LEDs (). Each of the next lines contains two space-separated integers and (, ), meaning that the anode of the -th LED is connected to controller output and its cathode to output .
Output
For each LED, print one line. If the controller outputs can be set to voltages so that only the -th LED lights up, print JAH on the -th line. Otherwise print EI.