guards. There are two types of guards, ones with bulletproof armour and ones with fireproof armour. has two weapons, Molotov cocktails and shotguns. Unfortunately,
pairs of guards are one-way friends with each other, therefore must kill some guards before others. He would like to know the minimum number of times he needs to change weapons while following the order of friendships.
Input Specification
Line :
and
(
)
Line :
integers, either
or
, representing the type of each guard
Lines : 2 integers
and
, representing that
must be killed before
It is guaranteed that it will be possible to kill all guards. There may be multiple connections between the same pair.
Output Specification
Print on the first line the minimum number of times
is required to change his weapon.Sample Input
6 4
0 1 0 1 1 1
0 1
3 2
1 2
2 5
Sample Output
3
Comments