Problem p02761 (python)

Fixed submission:
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
if n == 1:
    if m == 0:
        print(0)
        sys.exit()
    else:
        for i in range(m):
            s,c = map(int,input().split())
            if ans[s-1] == -1:
                ans[s-1] = c
            else:
                if c == ans[s-1]:
                    continue
                else:
                    print(-1)
                    sys.exit()
        print(ans[0])
else:
    for i in range(m):
        s,c = map(int,input().split())
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
            else:
                if ans[s-1] == -1:
                    ans[s-1] = c
                else:
                    if c == ans[s-1]:
                        continue
                    else:
                        print(-1)
                        sys.exit()
        else:
            if ans[s-1] == -1:
                    ans[s-1] = c
            else:
                if c == ans[s-1]:
                        continue
                else:
                    print(-1)
                    sys.exit()
    if ans[0] == -1:
        ans[0] = 1
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
    ans2 = ""
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    s-=1
    if ans[s] == -1:
        ans[s] = c
    else:
        if c == ans[s]:
            continue
        else:
            print(-1)
            sys.exit()
    if n != 1:
        if ans[s] == 0:
            print(-1)
            sys.exit()
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
fans = ""
for i in range(n):
    fans += ans[i]
print(fans)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    else:
        if c == ans[s-1]:
            continue
        else:
            print(-1)
            sys.exit()
    if s-1 == 0:
        if c == 0:
            print(-1)
            sys.exit()
if n == 1:
    print(c)
elif n == 2:
    if ans[0] == -1:
        ans[0] = 1
else:
    if ans[0] == -1:
        ans[0] = 1
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
ans2 = ''
for i in range(n):
    ans2 += str(ans[i])
print(ans2)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
if n == 1:
    s,c = map(int,input().split())
    print(c)
    sys.exit()
else:
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if c == ans[s-1]:
                continue
            else:
                print(-1)
                sys.exit()
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
    for i in range(1,n+1):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == -1:
        ans[0] = 1
    ans2 = ''
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
if n == 1:
    s,c = map(int,input().split())
    print(c)
    sys.exit()
else:
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if c == ans[s-1]:
                continue
            else:
                print(-1)
                sys.exit()
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
    for i in range(1,n):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == -1:
        ans[0] = 1
    ans2 = ''
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
if n == 1:
    s,c = map(int,input().split())
    print(c)
else:
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if c == ans[s-1]:
                continue
            else:
                print(-1)
                sys.exit()
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
    for i in range(1,n):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == -1:
        ans[0] = 1
    ans2 = ''
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
if n == 1:
    s,c = map(int,input().split())
    print(c)
else:
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if c == ans[s-1]:
                continue
            else:
                print(-1)
                sys.exit()
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
    ans2 = ''
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)