Problem p02761 (python)

Fixed submission:
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    if M == 0:
        if N != 1:
            print(10**(N-1))
        else:
            print(0)
    else:
        ans = "-1"
        flag = False
        for i in range(10**N):
            if flag:
                break
            tmp = str(i)
            if len(tmp) < N:
                continue
            for j in range(M):
                if tmp[sc[j][0]-1] != str(sc[j][1]):
                    break
                if j == M-1:
                    ans = i
                    flag = True
        print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    ans = "-1"
    for i in range(10**N):
        tmp = str(i)
        if len(tmp) < N:
            continue
        for j in range(M):
            if tmp[sc[j][0]-1] != str(sc[j][1]):
                break
        if j == M-1 and ans == "-1":
            ans = i
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    tmp = [[] for _ in range(N)]
    for i in range(M):
        s,c = sc[i][0],sc[i][1]
        tmp[s-1].append(c)
    ans = []
    for i in range(N):
        if len(set(tmp[i])) >= 2:
            ans = "-1"
            break
    if ans == "-1":
        print(ans)
    else:
        cc = []
        for i in range(1000):
            st = list(str(i))
            for j in range(N):
                if len(tmp[j]) == 0 or len(st) < N:
                    continue
                if st[j] != str(tmp[j][0]):
                    ans = "-1"
                    break
                if j == N-1 and len(st) == N:
                    cc.append(i)
        print(cc)[0]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = "-1"
    if N == 1:
        for i in range(10):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    elif N == 2:
        for i in range(10,100):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    else:
        for i in range(100,1000):
            if ans != "-1":
                break
            strnum = list(str(i))
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
                if j == M-1:
                    ans = i
                    break
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = [0]*max(s)
    ans[0] = 1
    for i in range(M):
        if s[i]-1 == 0:
            if ans[0] == 1 or ans[0] == c[i]:
                ans[0] = c[i]
            else:
                ans = "-1"
                break
        if ans[s[i]-1] == 0 or ans[s[i]-1] == c[i]:
            ans[s[i]-1] = c[i]
        else:
            ans = "-1"
            break
    if ans == "-1":
        print("-1")
    else:
        ans = list(map(str,ans))
        if ans == ["0"]:
            print("-1")
        else:
            print(*ans,sep="")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = [0]*max(s)
    ans[0] = 1
    for i in range(M):
        if s[i]-1 == 0:
            if ans[0] == 1 or ans[0] == c[i]:
                ans[0] = c[i]
            else:
                ans = "-1"
                break
        if ans[s[i]-1] == 0 or ans[s[i]-1] == c[i]:
            ans[s[i]-1] = c[i]
        else:
            ans = "-1"
            break
    if ans == "-1":
        ans == "-1"
    else:
        ans = list(map(str,ans))
        if ans == ["0"]:
            print("-1")
        else:
            print(*ans,sep="")

if __name__ == '__main__':
    main()