Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or ls_1[0] == 0:
    print(-1)
else:
    if len(ls_1) == 0:
        if N > 1:
            ls_1.append(1)
        else:
            ls_1.append(0)
    if len(ls_2) == 0:
        ls_2.append(0)
    if len(ls_3) == 0:
        ls_3.append(0)
    
    ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
    print(ans)

Fixed submission:
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or (N > 1 and len(ls_1) > 0 and sum(ls_1)==0):
    print(-1)
else:
    if len(ls_1) == 0:
        if N > 1:
            ls_1.append(1)
        else:
            ls_1.append(0)
    if len(ls_2) == 0:
        ls_2.append(0)
    if len(ls_3) == 0:
        ls_3.append(0)
    
    ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
    print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or ls_1[0] == 0:
    print(-1)
    sys.exit()
if len(ls_1) == 0:
    ls_1.append(1)
if len(ls_2) == 0:
    ls_2.append(0)
if len(ls_3) == 0:
    ls_3.append(0)
    
ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
print(ans)

Fixed submission:
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or (N > 1 and len(ls_1) > 0 and sum(ls_1)==0):
    print(-1)
else:
    if len(ls_1) == 0:
        if N > 1:
            ls_1.append(1)
        else:
            ls_1.append(0)
    if len(ls_2) == 0:
        ls_2.append(0)
    if len(ls_3) == 0:
        ls_3.append(0)
    
    ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
    print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or ls_1[0] == 0:
    print(-1)
    sys.exit()
if len(ls_1) == 0:
    ls_1.append(1)
if len(ls_2) == 0:
    ls_2.append(0)
if len(ls_3) == 0:
    ls_3.append(0)
    
ans = 100 * ls_1[0] + 10 * ls_2[0] + ls_3[0]
print(ans)

Fixed submission:
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or (N > 1 and len(ls_1) > 0 and sum(ls_1)==0):
    print(-1)
else:
    if len(ls_1) == 0:
        if N > 1:
            ls_1.append(1)
        else:
            ls_1.append(0)
    if len(ls_2) == 0:
        ls_2.append(0)
    if len(ls_3) == 0:
        ls_3.append(0)
    
    ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
    print(ans)