This page is still under construction.

Parts of this page are still being built. What you see may change.

I can solve problem 9999

Time limit1sMemory limit128 MB

Summary
Choose yes or no votes for everyone to minimize disagreeing friendships plus votes cast against personal belief.
Level

Medium7 of 10

Topics
Graph
Solved
No attempts yet

Problem

People are voting on whether Minhyuk can solve problem 9999. Most of them vote the way they actually think, but some vote against their own belief to avoid disagreeing with a friend.

You are given what each person believes about Minhyuk and problem 9999, together with the friendships among them.

Once the vote is over, add two numbers. The first is the number of friendships whose two members voted differently, and the second is the number of people who voted against their own belief. Write a program that finds the smallest value this sum can take.

Input

The input consists of several test cases.

The first line of each test case has the number of people NN and the number of friendships MM. (2≤N≤3002 \le N \le 300, 0≤M≤N(N−1)/20 \le M \le N(N-1)/2)

The second line has NN numbers describing what each person believes, given in order starting from person 1. A 1 is a person who believes Minhyuk can solve problem 9999, and a 0 is a person who believes he cannot.

Each of the next MM lines has the numbers of two people who are friends. People are numbered from 1 to NN.

The last line of the input is N=M=0N = M = 0, and that line is not a test case.

Output

For each test case, print on one line the minimum value of the number of friendships whose two members voted differently plus the number of people who voted against their own belief.

Hint

In the first test case of the example, only person 1 has to vote against their own belief. In the second test case, everyone votes the way they think.

Examples1

  1. Example 1

    Input
    3 3
    1 0 0
    1 2
    1 3
    3 2
    6 6
    1 1 1 0 0 0
    1 2
    2 3
    4 2
    3 5
    4 5
    5 6
    0 0
    
    Expected output
    1
    2