Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split(" "))

if(M==0):
    if(N==1):
        print(0)
    elif(N==2):
        print(10)
    elif(N==3):
        print(100)
    exit()



listing=[]

for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))




a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()
num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit1=digit
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

listing=[]
for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))


if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()

a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit1=digit
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

listing=[]
for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))

for i in aa:
    



if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()



a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit1=1
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

listing=[]
for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))

for i in aa:
    



if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()



a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit=1
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

listing=[]
for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)

#listing.sort()
#print(listing)
aa=list(map(list, set(map(tuple, listing))))
#aa.sort()


if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()
elif(N==1):
    print(0)
    exit()


a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

listing=[]
for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)

#listing.sort()
#print(listing)
aa=list(map(list, set(map(tuple, listing))))
#aa.sort()

for i in aa:
    if(i[0]>N):
        print(-1)
        exit()

if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()
elif(N==1):
    print(0)
    exit()


a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

s=[]
for i in range(M):
    s.append(list(map(int,input().split(" "))))

s.sort()

if(N==1 and s[0][0]==1):
    print(s[0][1])
    exit()
elif(N==1 and s[0][0]!=1):
    print(-1)
    exit()


numlist=[0,0,0]

for i in s:

    if(numlist[i[0]-1]!=0 and numlist[i[0]-1]!=i[1]):
        print(-1)
        exit()
    else:
        if(i[0]>N):
            print(-1)
            exit()
        numlist[i[0]-1]=i[1]

if(numlist[0]==0):
    print(-1)
    exit()

num=""
for i in range(N):
    num+=str(numlist[i])
    
print(num)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(" "))

s=[]
for i in range(M):
    s.append(list(map(int,input().split(" "))))

s.sort()

if(N==1 and s[0][0]==1):
    print(s[0][1])
    exit()
elif(N==1 and s[0][0]!=1):
    print(-1)
    exit()
numlist=[0,0,0]

for i in s:

    if(numlist[i[0]-1]!=0 and numlist[i[0]-1]!=i[1]):
        print(-1)
        exit()
    else:
        numlist[i[0]-1]=i[1]

if(numlist[0]==0):
    print(-1)
    exit()

num=""
for i in range(N):
    num+=str(numlist[i])
    
print(num)