Problem p02761 (python)

Fixed submission:
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            if int(str(i)[s[j] - 1]) != c[j]:
                    flg = False
        if flg:
            print(i)
            break
if not flg:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s)
if digit == 1:
    start = 0
else:
    start = 10 ** (digit - 1)


ans = []

for i in range(start, 10 ** 3):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j] - 1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1 and len(num) == n:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s)

ans = []

if digit == 1:
    for i in range(10):
        num = str(i)
        flg = 0
        for j in range(m):
            if num[s[j] - 1] == str(c[j]):
                flg = 1
            else:
                flg = 0
                break
        if flg == 1:
            ans.append(i)
else:
    for i in range(10 ** (digit - 1), 10 ** digit):
        num = str(i)
        flg = 0
        for j in range(m):
            if num[s[j] - 1] == str(c[j]):
                flg = 1
            else:
                flg = 0
                break
        if flg == 1:
            ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s)

ans = []

for i in range(10 ** (digit - 1) + 1,10 ** digit):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s)

ans = []

for i in range(10 ** digit + 1,10 ** (digit + 1)):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s) - min(s)

ans = []

for i in range(10 ** digit + 1,10 ** (digit + 1)):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s) - min(s)

ans = []

for i in range(10 ** digit + 1,10 ** (digit + 1)):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

print(min(ans))