Lee bought some food for dinner time, but Lee's friends eat dinner in a deadly way. Lee is so scared, he doesn't want to die, at least not before seeing Online IOI 2020...

There are $n$ different types of food and $m$ Lee's best friends. Lee has $w_i$ plates of the $i$-th type of food and each friend has two different favorite types of food: the $i$-th friend's favorite types of food are $x_i$ and $y_i$ ($x_i \ne y_i$).

Lee will start calling his friends one by one. Whoever is called will go to the kitchen and will try to eat one plate of each of his favorite food types. Each of the friends will go to the kitchen exactly once.

The only problem is the following: if a friend will eat at least one plate of food (in total) then he will be harmless. But if there is nothing left for him to eat (neither $x_i$ nor $y_i$), he will eat Lee instead $\times\_\times$.

Lee can choose the order of friends to call, so he'd like to determine if he can survive dinner or not. Also, he'd like to know the order itself.


-----Input-----

The first line contains two integers $n$ and $m$ ($2 \le n \le 10^5$; $1 \le m \le 2 \cdot 10^5$) — the number of different food types and the number of Lee's friends. 

The second line contains $n$ integers $w_1, w_2, \ldots, w_n$ ($0 \le w_i \le 10^6$) — the number of plates of each food type.

The $i$-th line of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$; $x_i \ne y_i$) — the favorite types of food of the $i$-th friend. 


-----Output-----

If Lee can survive the dinner then print ALIVE (case insensitive), otherwise print DEAD (case insensitive).

Also, if he can survive the dinner, print the order Lee should call friends. If there are multiple valid orders, print any of them.


-----Examples-----
Input
3 3
1 2 1
1 2
2 3
1 3

Output
ALIVE
3 2 1 

Input
3 2
1 1 0
1 2
1 3

Output
ALIVE
2 1 

Input
4 4
1 2 0 1
1 3
1 2
2 3
2 4

Output
ALIVE
1 3 2 4 

Input
5 5
1 1 1 2 1
3 4
1 2
2 3
4 5
4 5

Output
ALIVE
5 4 1 3 2 

Input
4 10
2 4 1 4
3 2
4 2
4 1
3 1
4 1
1 3
3 2
2 1
3 1
2 4

Output
DEAD



-----Note-----

In the first example, any of the following orders of friends are correct : $[1, 3, 2]$, $[3, 1, 2]$, $[2, 3, 1]$, $[3, 2, 1]$.

In the second example, Lee should call the second friend first (the friend will eat a plate of food $1$) and then call the first friend (the friend will eat a plate of food $2$). If he calls the first friend sooner than the second one, then the first friend will eat one plate of food $1$ and food $2$ and there will be no food left for the second friend to eat.

Difficulty: interview

Starter code:

Solutions:
def xmax(x, y):
    if x[1] > y[1]:
        return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k
        k += self.num-1
        self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

import sys;input=sys.stdin.readline
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = list(map(int, input().split()))
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f = False
R = []
vs = set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:
        f=True
        break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:
            continue
        vs.add(i)
        ss.update(co, 1)
        R.append(i)
    if len(R) == M:
        break
    ss.update2(j, (j, minf))

if f or len(R) != M:
    print("DEAD")
else:
    print("ALIVE")
    print(*R[::-1])


def xmax(x, y):
    if x[1] > y[1]:
        return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k
        k += self.num-1
        self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

import sys;input=sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = map(int, input().split())
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f = False
R = []
vs = set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:
        f=True
        break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:
            continue
        vs.add(i)
        ss.update(co, 1)
        R.append(i)
    if len(R) == M:
        break
    ss.update2(j, (j, minf))

if f or len(R) != M:
    print("DEAD")
else:
    print("ALIVE")
    print(*R[::-1])

def xmax(x, y):
    if x[1] > y[1]:
        return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k
        k += self.num-1
        self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

import sys;input=sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = map(int, input().split())
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f = False
R = []
vs = set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:
        f=True
        break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:
            continue
        vs.add(i)
        ss.update(co, 1)
        R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))

if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

from collections import deque
import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    ww=LI()
    xy=LLI1(m)
    fav_mem=[[] for _ in range(n)]
    fav_cnt=[0]*n
    for j,(x,y) in enumerate(xy):
        fav_mem[x].append(j)
        fav_mem[y].append(j)
        fav_cnt[x]+=1
        fav_cnt[y]+=1

    q=deque()
    for i in range(n):
        if ww[i]-fav_cnt[i]>=0:q.append(i)

    ans=[]
    fini=[False]*n
    finj=[False]*m
    while q:
        i=q.popleft()
        for j in fav_mem[i]:
            if finj[j]:continue
            ans.append(j+1)
            finj[j]=True
            for i0 in xy[j]:
                if fini[i0]:continue
                fav_cnt[i0]-=1
                if  ww[i0]-fav_cnt[i0]>=0:
                    q.append(i0)
                    fini[i0]=True
    if len(ans)==m:
        print("ALIVE")
        print(*ans[::-1])
    else:print("DEAD")

main()

def xmax(x, y):
    if x[1] > y[1]:return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k
        k += self.num-1
        self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

import sys;input=sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = map(int, input().split())
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f = False
R = []
vs = set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:
        f=True
        break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:continue
        vs.add(i)
        ss.update(co, 1)
        R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))

if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

def xmax(x, y):
    if x[1] > y[1]:return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k
        k += self.num-1
        self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:res = self.segfunc(res,self.seg[p])
            if q&1 == 1:res = self.segfunc(res,self.seg[q]);q -= 1
            p = p//2
            q = (q-1)//2
        res = (self.segfunc(res,self.seg[p]) if p == q else self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]))
        return res

import sys;input=sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = map(int, input().split())
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f,R,vs = False,[],set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:f=True;break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:continue
        vs.add(i);ss.update(co, 1);R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))

if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

def xmax(x, y):
    if x[1] > y[1]:return x
    return y

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func;self.num = 2**(n-1).bit_length();self.ide_ele = ide_ele;self.seg=[self.ide_ele]*2*self.num
        for i in range(n):self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        ll = k;k += self.num-1;self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])

    def update2(self, k, x):
        k += self.num-1;self.seg[k] = x
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:return self.ide_ele
        p += self.num-1;q += self.num-2;res=self.ide_ele
        while q-p>1:
            if p&1 == 0:res = self.segfunc(res,self.seg[p])
            if q&1 == 1:res = self.segfunc(res,self.seg[q]);q -= 1
            p = p//2;q = (q-1)//2
        return (self.segfunc(res,self.seg[p]) if p == q else self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]))

import sys;input=sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
sts = [[] for _ in range(N)]
for i in range(1, M+1):
    a, b = map(int, input().split())
    sts[a-1].append((i, b-1))
    sts[b-1].append((i, a-1))
    X[a-1] -= 1
    X[b-1] -= 1
minf = -(10 ** 18)-1
ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax)
f,R,vs = False,[],set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:f=True;break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:continue
        vs.add(i);ss.update(co, 1);R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))

if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

def xmax(x, y):
    if x[1] > y[1]:return x
    return y
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func;self.num = 2**(n-1).bit_length();self.ide_ele = ide_ele;self.seg=[self.ide_ele]*2*self.num
        for i in range(n):self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2])         
    def update(self, k, x):
        ll = k;k += self.num-1;self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
    def update2(self, k, x):
        k += self.num-1;self.seg[k] = x
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])        
    def query(self, p, q):
        if q<=p:return self.ide_ele
        p += self.num-1;q += self.num-2;res=self.ide_ele
        while q-p>1:
            if p&1 == 0:res = self.segfunc(res,self.seg[p])
            if q&1 == 1:res = self.segfunc(res,self.seg[q]);q -= 1
            p = p//2;q = (q-1)//2
        return (self.segfunc(res,self.seg[p]) if p == q else self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]))
import sys;input=sys.stdin.readline
N, M = map(int, input().split());X = list(map(int, input().split()));sts = [[] for _ in range(N)]
for i in range(1, M+1):a, b = map(int, input().split());sts[a-1].append((i, b-1));sts[b-1].append((i, a-1));X[a-1] -= 1;X[b-1] -= 1
minf = -(10 ** 18)-1;ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax);f,R,vs = False,[],set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:f=True;break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:continue
        vs.add(i);ss.update(co, 1);R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))
if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

def xmax(x, y):
    if x[1] > y[1]:return x
    return y
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func;self.num = 2**(n-1).bit_length();self.ide_ele = ide_ele;self.seg=[self.ide_ele]*2*self.num
        for i in range(n):self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2])         
    def update(self, k, x):
        ll = k;k += self.num-1;self.seg[k] = (ll, self.seg[k][1] + x)
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
    def update2(self, k, x):
        k += self.num-1;self.seg[k] = x
        while k+1:k = (k-1)//2;self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])        
    def query(self, p, q):
        if q<=p:return self.ide_ele
        p += self.num-1;q += self.num-2;res=self.ide_ele
        while q-p>1:
            if p&1 == 0:res = self.segfunc(res,self.seg[p])
            if q&1 == 1:res = self.segfunc(res,self.seg[q]);q -= 1
            p = p//2;q = (q-1)//2
        return (self.segfunc(res,self.seg[p]) if p == q else self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]))
import sys;input=sys.stdin.readline;N, M = map(int, input().split());X = list(map(int, input().split()));sts = [[] for _ in range(N)]
for i in range(1, M+1):a, b = map(int, input().split());sts[a-1].append((i, b-1));sts[b-1].append((i, a-1));X[a-1] -= 1;X[b-1] -= 1
minf = -(10 ** 18)-1;ss = SegTree([(i, x) for i, x in enumerate(X)], N, (-1, minf), xmax);f,R,vs = False,[],set()
while True:
    j, mx = ss.query(0, N)
    if mx<0:f=True;break
    while sts[j]:
        i, co = sts[j].pop()
        if i in vs:continue
        vs.add(i);ss.update(co, 1);R.append(i)
    if len(R) == M:break
    ss.update2(j, (j, minf))
if f or len(R) != M:print("DEAD")
else:print("ALIVE");print(*R[::-1])

import sys
from collections import deque

input=sys.stdin.readline


n,m=list(map(int,input().split()))
w=list(map(int,input().split()))
data=[[] for i in range(n)]
fav=[]
for i in range(m):
    x,y=list(map(int,input().split()))
    x,y=min(x,y),max(x,y)
    w[x-1]-=1
    w[y-1]-=1
    data[x-1].append(i)
    data[y-1].append(i)
    fav.append((x-1,y-1))

ans=[]
used=[False]*m
useddish=[False]*n

que=deque([])
for i in range(n):
    if w[i]>=0:
        que.append(i)
        useddish[i]=True

while que:
    id=que.popleft()
    for i in data[id]:
        if not used[i]:
            used[i]=True
            ans.append(i)
            x,y=fav[i]
            w[x]+=1
            w[y]+=1
            if w[x]>=0 and not useddish[x]:
                que.append(x)
                useddish[x]=True
            if w[y]>=0 and not useddish[y]:
                que.append(y)
                useddish[y]=True

if len(ans)==m:
    print("ALIVE")
    ans=[ans[-i-1]+1 for i in range(m)]
    print(*ans)
else:
    print("DEAD")


import math
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
w = [int(_) for _ in input().split()]
edges = []
g = [[] for _ in range(n)]
deg = [0] * n
for i in range(m):
    u, v = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append(v)
    g[v].append(u)
    edges.append((u, v))
    deg[u] += 1
    deg[v] += 1
order = [0] * n
done = [False] * n 
stack = []
cur = 0
for i in range(n):
    if deg[i] <= w[i]:
        done[i] = True
        order[i] = cur
        stack.append(i)
        cur += 1
while len(stack) > 0:
    x = stack.pop()
    for i in g[x]:
        deg[i] -= 1
        if not done[i] and deg[i] <= w[i]:
            order[i] = cur
            done[i] = True
            stack.append(i)
            cur += 1
if sum(done) != n:
    print('DEAD')
    return
sortEdges = []
for i in range(m):
    u, v = edges[i]
    if order[u] < order[v]:
        u, v = v, u
    sortEdges.append((order[u], order[v], i))
print('ALIVE')
print(' '.join([str(i[2] + 1) for i in sorted(sortEdges, reverse=True)]))