Problem p02761 (python)

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

reslist = []

if M == 0:
    if N == 1:
        print(0)
        exit(0)
    else:
        print('1' + '0'*(N-1))
        exit(0)

slist = [list(map(int,input().split())) for i in range(M)]

mlist = [-1 for i in range (N+1)]

for lis in slist:
    if mlist[lis[0]] != -1:
        if mlist[lis[0]] != lis[1]:
            print(-1)
            exit(0)
    else:
        mlist[lis[0]] = lis[1]

# print(mlist)



for j in range(1, N+1):
    # print(mlist[j])
    if mlist[j] == 0 and N > 1 and j == 1:
        print(-1)
        exit(0)
    if mlist[j] == -1:
        if j == 1:
            reslist.append(1)
        else:
            reslist.append(0)
    else:
        reslist.append(mlist[j])

# print(reslist)

print("".join(map(str,reslist)))

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

reslist = []

if M == 0:
    if N == 1:
        print(0)
        exit(0)
    else:
        print('1' + '0'*(N-1))
        exit(0)

slist = [list(map(int,input().split())) for i in range(M)]

mlist = [-1 for i in range (M+1)]

for lis in slist:
    if mlist[lis[0]] != -1:
        if mlist[lis[0]] != lis[1]:
            print(-1)
            exit(0)
    else:
        if lis[0] == 1 and lis[1] == 0:
            print(-1)
            exit(0)
        mlist[lis[0]] = lis[1]

# print(mlist)



for j in range(1, N+1):
    # print(mlist[j])
    if mlist[j] == -1:
        if j == 1:
            reslist.append(1)
        else:
            reslist.append(0)
    else:
        reslist.append(mlist[j])

# print(reslist)

print("".join(map(str,reslist)))

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

reslist = []

if M == 0:
    if N == 1:
        print(0)
        exit(0)
    else:
        print('1' + '0'*(N-1))
        exit(0)

slist = [list(map(int,input().split())) for i in range(M)]

mlist = [-1 for i in range (M+1)]

for lis in slist:
    if mlist[lis[0]] != -1:
        if mlist[lis[0]] != lis[1]:
            print(-1)
            exit(0)
    else:
        if lis[0] == 1 and lis[1] == 0:
            print(-1)
            exit(0)
        mlist[lis[0]] = lis[1]

# print(mlist)



for j in range(1, M+1):
    # print(mlist[j])
    if mlist[j] == -1:
        if j == 1:
            reslist.append(1)
        else:
            reslist.append(0)
    else:
        reslist.append(mlist[j])

# print(reslist)

print("".join(map(str,reslist)))

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

if M == 0:
    print(0)
    exit(0)

slist = [list(map(int,input().split())) for i in range(M)]

mlist = [-1 for i in range (M+1)]

for lis in slist:
    if mlist[lis[0]] != -1:
        if mlist[lis[0]] != lis[1]:
            print(-1)
            exit(0)
    else:
        if lis[0] == 1 and lis[1] == 0:
            print(-1)
            exit(0)
        mlist[lis[0]] = lis[1]

# print(mlist)

reslist = []

for j in range(1, M+1):
    # print(mlist[j])
    if mlist[j] == -1:
        if j == 1:
            reslist.append(1)
        else:
            reslist.append(0)
    else:
        reslist.append(mlist[j])

# print(reslist)

print("".join(map(str,reslist)))