Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
if M == 0:
    if N ==3:
        sum = 100
    elif N ==2:
        sum = 10
    elif N ==1:
        sum = 0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i]*100)
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
if M == 0:
    if N ==3:
        sum = 100
    elif N ==2:
        sum = 10
    else: 
        sum = 1
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i]*100)
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
if M == 0:
    lastcheck =0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i]*100)
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
elif N==1:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    lastcheck = 0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i]*100)
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
for i in range (M):
    print(Si[i])
    print(Ci[i])
if N==1:
    for i in range (M):
        sum +=C[i]
        if Si[i]==1 and Ci[i]==0:
            lastcheck=0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i]*100)
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=C[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)
            

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
Si = []
Ci = []
check1 = 0
check2 = 0
check3 = 0
lastcheck = 0
sum = 0
for i in range(M):
    S,C = map(int, input().split())
    Si.append(S)
    Ci.append(C)
if N==1:
    for i in range (M):
        sum +=C[i]
        check3  = i
        if C[i] != C[check3]:
            lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 2:
            sum +=C[i]*10
            check2 = i
            if C[i] != C[check2]:
                lastcheck=0
        else:
            sum +=C[i]
            check3=i
            if C[i] != C[check3]:
                lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            sum+=int(Ci[i]*100)
            check1 = i
            if int(C[i]) != int(C[check1]):
                lastcheck=0
        elif Si[i] == 2:
            sum +=C[i]*10
            check2 = i
            if C[i] != C[check2]:
                lastcheck=0
        else:
            sum +=C[i]
            check3=i
            if C[i] != C[check3]:
                lastcheck=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)
            

Fixed submission:
N,M = map(int, input().split())
Si = [0]*M
Ci = [0]*M
lastcheck = 1
precheck = 0
sum = 0
for i in range(M):
    Si[i], Ci[i] = map(int, input().split())
if N==1:
    for i in range (M):
        sum +=Ci[i]
        if Si[i]==1 and Ci[i]==0:
            sum =0
        for j in range(i+1,M):
            if Si[i]==Si[j]:
                sum-=int(Ci[i])
                if Ci[i] != Ci[j]:
                    lastcheck=0
elif N==2:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
else:
    for i in range (M):
        if Si[i] == 1:
            if Si[i]==1 and Ci[i]==0:
                lastcheck=0
            sum+=int(Ci[i]*100)
            for j in range(i+1,M):
                if Si[i]==Si[j]:
                    sum-=int(Ci[i]*100)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        elif Si[i] == 2:
            sum +=Ci[i]*10
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i]*10)
                    if Ci[i] != Ci[j]:
                        lastcheck=0
        else:
            sum +=Ci[i]
            for j in range(i+1,M):
                if Si[i] == Si[j]:
                    sum-=int(Ci[i])
                    if Ci[i] != Ci[j]:
                        lastcheck=0
for i in range(M):
    if Si[i] == 1:
        precheck+=1
if precheck == 0:
    if N == 3:
        sum +=100
    elif N == 2:
        sum +=10
    else:
        sum+=0
if lastcheck == 0:
    print('-1')
else:
    print(sum)