ZhenlongDai/ACPR huggingface dataset:
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

N, M = map(int, input().split())
a = [[0] * 10] * 3

for i in range(N):
  if i == 0:
    a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  else:
    a[i] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

flag = 1

for i in range(M):
  s, c = map(int, input().split())
  if (s == 1 and c == 0) or (len(a[s-1]) == 1 and a[s-1] != [c]):
    flag = 0
  a[s-1] = [c]

if flag == 0:
  print(-1)
else:
  list_a = list(itertools.product(*a))
  ans = ""
  for i in range(N):
    ans += str(list_a[0][i])
  print(int(ans))

Failing test case input:
2 1
0 3
2 2

Expected output:
13


Actual output:
10


Fixed submission (verdict: Accepted):
import itertools
 
N, M = map(int, input().split())
a = [[0] * 10] * N
 
for i in range(N):
  if i == 0:
    a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  else:
    a[i] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
flag = 1
 
for i in range(M):
  s, c = map(int, input().split())
  if (N > 1 and s == 1 and c == 0) or (len(a[s-1]) == 1 and a[s-1] != [c]):
    flag = 0
  a[s-1] = [c]
 
if N == 1 and M == 0:
  print(0)
elif flag == 0:
  print(-1)
else:
  list_a = list(itertools.product(*a))
  ans = ""
  for i in range(N):
    ans += str(list_a[0][i])
  print(int(ans))

Problem: p02761
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
N, M = list(map(int, input().split()))
digits = [-1] * N
for _ in range(M):
    s, c = list(map(int, input().split()))
    s -= 1

    if digits[s] == -1 or (digits[s] != 1 and digits[s] == c):
        digits[s] = c
    else:
        print(-1)
        sys.exit(0)

if digits[0] == 0 and N != 1:
    print(-1)
    sys.exit(0)


n = 0
base = 1
for i in reversed(range(N)):
    if digits[i] != -1:
        n += base * digits[i]
    elif i == 0 and digits[i] == -1:
        n += base 
    base *= 10

print(n)


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):

import sys
N, M = list(map(int, input().split()))
digits = [-1] * N
for _ in range(M):
    s, c = list(map(int, input().split()))
    s -= 1

    if digits[s] == -1 or (digits[s] != 1 and digits[s] == c):
        digits[s] = c
    else:
        print(-1)
        sys.exit(0)

if digits == [-1]:
    print(0)
    sys.exit(0)
    
if digits[0] == 0 and N != 1:
    print(-1)
    sys.exit(0)


n = 0
base = 1
for i in reversed(range(N)):
    if digits[i] != -1:
        n += base * digits[i]
    elif i == 0 and digits[i] == -1:
        n += base
    base *= 10

print(n)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
[n,m] = [int(i) for i in input().split()]
data = []
ans = [-1] * n
flag = False
for _ in range(m):
    data.append([int(i) for i in input().split()])
for q in data:
    if ans[q[0]-1] == -1 or ans[q[0]-1] == q[1]:
        ans[q[0]-1] = q[1]
    else:
        flag = True
        break
if flag:
    print(-1)
elif ans == [0]:
    print(0)
elif ans[0] == 0:
    print(-1)
else:
    fa = ["0" if ans[i] == -1 else str(ans[i]) for i in range(n)]
    if fa[0] == 0:
        fa[0] = 1
    print("".join(fa))


Failing test case input:
3 0
2 1
2 -1

Expected output:
100


Actual output:
000


Fixed submission (verdict: Accepted):
[n,m] = [int(i) for i in input().split()]
data = []
ans = [-1] * n
flag = False
for _ in range(m):
    data.append([int(i) for i in input().split()])
for q in data:
    if ans[q[0]-1] == -1 or ans[q[0]-1] == q[1]:
        ans[q[0]-1] = q[1]
    else:
        flag = True
        break
if flag:
    print(-1)
elif ans == [0] or ans == [-1]:
    print(0)
elif ans[0] == 0:
    print(-1)
else:
    fa = ["0" if ans[i] == -1 else str(ans[i]) for i in range(n)]
    if fa[0] == "0":
        fa[0] = "1"
    print("".join(fa))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
conditions = [list(map(int,input().split())) for i in range(M)]

for i in range(10**(N-1) ,10 ** N):
    isOk = False
    
    for j,c in enumerate(conditions):
        s = str(i)
        
        
        
        if c[0] > len(s):
            break
        if str(c[1]) != s[c[0]-1]:
            break
        if j == M -1:
            isOk = True

    if isOk:
        print(i)
        exit(0)

print(-1)
exit(0)

Failing test case input:
3 0
2 0
2 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
conditions = [list(map(int,input().split())) for i in range(M)]
if M == 0 and N == 1:
    print(0)
    exit(0)

if M == 0 and N == 2:
    print(10)
    exit(0)

if M == 0 and N == 3:
    print(100)
    exit(0)

for i in range(0 if N == 1 else 10**(N-1) ,10 ** N):
    isOk = False
    
    for j,c in enumerate(conditions):
        s = str(i)
        
        
        
        if c[0] > len(s):
            break
        if str(c[1]) != s[c[0]-1]:
            break
        if j == M - 1:
            isOk = True

    if isOk:
        print(i)
        exit(0)

print(-1)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
keta=[-1]*N
a=[]
for i in range(M):
    c1,c2=map(int,input().split())
    a.append([c1,c2])


for p in a:
    k=p[0]
    s=p[1]
    if keta[k-1] == -1:
        keta[k-1] = s
    elif keta[k-1] != s:
        print(-1)
        exit()

    
for i in range(10**(N-1),10**N):
    Q= str(i)
    flag=1
    for j in range(N):
        if keta[j]!= -1 and Q[j]==str(keta[j]):
            flag *= 1
        elif keta[j]!= -1 and Q[j] != str(keta[j]):
            flag *= 0

    if flag==1:
        print(i)
        break
else:
    print(0)

    


Failing test case input:
3 2
1 0
0 0

Expected output:
-1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
keta=[-1]*N
a=[]
for i in range(M):
    c1,c2=map(int,input().split())
    a.append([c1,c2])


for p in a:
    k=p[0]
    s=p[1]
    if keta[k-1] == -1:
        keta[k-1] = s
    elif keta[k-1] != s:
        print(-1)
        exit()


if N==1:
    for i in range(0,10**N):
        Q= str(i)
        flag=1
        for j in range(N):
            if keta[j]!= -1 and Q[j]==str(keta[j]):
                flag *= 1
            elif keta[j]!= -1 and Q[j] != str(keta[j]):
                flag *= 0

        if flag==1:
            print(i)
            exit()

    
    
for i in range(10**(N-1),10**N):
    Q= str(i)
    flag=1
    for j in range(N):
        if keta[j]!= -1 and Q[j]==str(keta[j]):
            flag *= 1
        elif keta[j]!= -1 and Q[j] != str(keta[j]):
            flag *= 0

    if flag==1:
        print(i)
        break
else:
    print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
ans=0
digit=[-1]*N
for i in  range(M):
    s,c=map(int,input().split())
    if digit[s-1]>=0 and digit[s-1]!=c:
        ans=-1
        break
    if s==1 and c==0 and N!=1:
        ans=-1
        break
    else:
        digit[s-1]=c

if ans!=-1:
    ans+=max(1,digit[0])*(10**(N-1))
    for j in range(1,N):
        if digit[j]!=-1:
            ans+=digit[j]*(10**(N-j-1))


print(ans)

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
ans=0
digit=[-1]*N
for i in  range(M):
    s,c=map(int,input().split())
    if digit[s-1]>=0 and digit[s-1]!=c:
        ans=-1
        break
    if s==1 and c==0 and N!=1:
        ans=-1
        break
    else:
        digit[s-1]=c

if ans!=-1:
    if N==1:
        ans+=max(0,digit[0])
    else:
        ans+=max(1,digit[0])*(10**(N-1))
    for j in range(1,N):
        if digit[j]!=-1:
            ans+=digit[j]*(10**(N-j-1))


print(ans)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
a = [0]*n
seen = [0]*n
flg = 0
ans = 0
for i in range(m):
  tmp = list(map(int,input().split()))
  if seen[tmp[0]-1] == 0:
    a[tmp[0]-1] = tmp[1]
    seen[tmp[0]-1] = 1
  else:
    if a[tmp[0]-1] == tmp[1]:
      pass
    else:
      flg = 1
if n != 1 and a[0] == 0 and seen[0] == 1:
  flg = 1
if flg == 1:
  print(-1)
else:
  if a[0] == 0:
    a[0] = 1
  print(''.join(map(str, a)))

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a = [0]*n
seen = [0]*n
flg = 0
ans = 0
for i in range(m):
  tmp = list(map(int,input().split()))
  if seen[tmp[0]-1] == 0:
    a[tmp[0]-1] = tmp[1]
    seen[tmp[0]-1] = 1
  else:
    if a[tmp[0]-1] == tmp[1]:
      pass
    else:
      flg = 1
if n != 1 and a[0] == 0 and seen[0] == 1:
  flg = 1
if flg == 1:
  print(-1)
else:
  if a[0] == 0 and n != 1:
    a[0] = 1
  print(''.join(map(str, a)))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
a = [list(map(int,input().split()))for i in range(m)]

for i in range(10**n):
    tmp = str(i)
    if len(tmp) == n:
        f = True
        for s,c in a:
            if tmp[s-1] != str(c):
                f = False
                break
            if f :
                print(i)
                exit()
print(-1)

Failing test case input:
3 3
1 2
1 2
0 2

Expected output:
202


Actual output:
200


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
a = [list(map(int,input().split()))for i in range(m)]

for i in range(10**n):
    tmp = str(i)
    if len(tmp) == n:
        f = True
        for s,c in a:
            if tmp[s-1] != str(c):
                f = False
                break
        if f :
            print(i)
            exit()
print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
t = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if t[x[i] - 1] == 0:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        if r[x[i] - 1] != y[i]:
            print(-1)
            exit()
if r[0] == 0 and t[0] == 0:
    r[0] = 1
elif n > 1 and r[0] == 0 and t[0] != 0:
    print(-1)
else:
    print(*r, sep='')


Failing test case input:
3 2
0 0
-1 0

Expected output:
100


Actual output:

Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
t = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if t[x[i] - 1] == 0:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        if r[x[i] - 1] != y[i]:
            print(-1)
            exit()
if n>1 and r[0] == 0 and t[0] == 0:
    r[0] = 1
elif n > 1 and r[0] == 0 and t[0] != 0:
    print(-1)
    exit()
print(*r, sep='')
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

n,m=map(int,input().split())
ans=["" for _ in range(n)]
for _ in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==c:
        continue
    elif ans[s-1]=="":
        ans[s-1]=c
    else:
        print(-1)
        exit()
if ans[0]==0:
    print(-1)
    exit()
for i in range(n):
    if ans[i]=="":
        if i!=0: ans[i]=0
        else: ans[i]=1
print("".join(map(str,ans)))

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
for i in range(1000):
    now=str(i)
    if len(now)!=n:
        continue
    ch=True
    for j in range(m):
        
        if int(now[a[j][0]-1])!=a[j][1]:
            ch=False
            break
    if ch:
        print(i)
        exit()
print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main(N,M,sc):
    ans=[-1]*N
    for x in sc:
        if (ans[x[0]-1] != -1 and ans[x[0]-1] != x[1]) or (x[0] == 1 and x[1] == 0):
            print(-1)
            return
        else:
            ans[x[0]-1] = x[1]
    for i,x in enumerate(ans):
        if x == -1:
            ans[i] = 0
    if N == 3:
        if ans[0] == 0 and ans[1] == 0:
            ans[0] = 1
            ans[1] = 0
        elif ans[0] == 0:
            ans[0] = 1
    else:
        if ans[0] == 0:
            ans[0] = 1
    print(*ans, sep='')

N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
main(N,M,sc)


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def main(N,M,sc):
    if (N,M) == (1,0) or ((N,M) == (1,1) and (sc[0][0] == 1 and sc[0][1] == 0)):
        print(0)
        return
    ans=[-1]*N
    for x in sc:
        if (ans[x[0]-1] != -1 and ans[x[0]-1] != x[1]) or (x[0] == 1 and x[1] == 0):
            print(-1)
            return
        else:
            ans[x[0]-1] = x[1]
    if ans[0] == -1:
        ans[0] = 1
    for i,x in enumerate(ans):
        if x == -1:
            ans[i] = 0
    print(*ans, sep='')

N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
main(N,M,sc)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print("-1")
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s = w[0]
        c = w[1]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ansb = [str(i) if i != -1 else str(0) for i in ans]
    anss = ''
    for s in ansb:
        anss = anss + s
    print(int(anss))

solution()


Failing test case input:
3 1
0 0
1 0

Expected output:
100


Actual output:
0


Fixed submission (verdict: Accepted):
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print(10**(n-1))
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s, c = w[0], w[1]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ansb = [str(i) if i != -1 else str(0) for i in ans]
    if (ansb[0] == '0') and (len(ansb) > 1):
        ansb[0] = '1'
    anss = ''
    for s in ansb:
        anss = anss + s
    print(anss)

solution()

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print("-1")
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s = w[0]
        c = w[1]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ans = [str(i) if i != -1 else str(0) for i in ans]
    anss = ''
    for s in ans:
        anss = anss + s
    print(int(anss))

solution()


Failing test case input:
3 0
3 1

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print(10**(n-1))
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s, c = w[0], w[1]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ansb = [str(i) if i != -1 else str(0) for i in ans]
    if (ansb[0] == '0') and (len(ansb) > 1):
        ansb[0] = '1'
    anss = ''
    for s in ansb:
        anss = anss + s
    print(anss)

solution()
Problem: p02761
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    num_list = list(range(10))
else:
    num_list = list(range(10**(n-1), 10**n))
        
for i in num_list:
    for j, (s, c) in enumerate(sc, 1):
        if str(i)[s-1] != str(c):
            break
        if j == m:
            print(i)
            exit()
print(-1)

Failing test case input:
3 0
2 1
2 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    num_list = list(range(10))
else:
    num_list = list(range(10**(n-1), 10**n))
        
for i in num_list:
    flg = True
    for s, c in sc:
        if str(i)[s-1] != str(c):
            flg = False
            break
    if flg:
        print(i)
        exit()
print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
num = [None]*N
res = 0
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if N > 1 and s == 0 and c == 0:
        res = -1
        break    
    if num[s] == None:
        num[s] = c
    elif num[s] != c:
        res = -1
        break

print(res) if res == -1 else print(*[e if e!=None else 0 if i != 0 else 1 for i, e in enumerate(num)], sep="")

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
num = [None]*N
res = 0
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if N > 1 and s == 0 and c == 0:
        res = -1
        break    
    if num[s] == None:
        num[s] = c
    elif num[s] != c:
        res = -1
        break

print(res) if res == -1 else print(*[e if e!=None else 0 if i != 0 or N == 1 else 1 for i, e in enumerate(num)], sep="")

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = list(map(int,input().split()))
s = []
c = []
for i in range(m):
    ss,cc = list(map(int,input().split()))
    s.append(ss -1 )
    c.append(cc)

ans = [-1] * n
flag = True
for i in range(m):
    if ans[s[i]] == -1 :
        ans[s[i]] = c[i]
    elif ans[s[i]] != c[i]:
        flag = False

if n !=1 and  ans[0] == 0:
    flag = False

if flag :
    ans = [ str(a) if a != -1 else "0" for a in ans ]
    if n != 1 and ans[0] == 0:
        ans[0] == 1
    print("".join(ans))
else:
    print(-1) 


Failing test case input:
3 1
2 0
0 1

Expected output:
100


Actual output:
000


Fixed submission (verdict: Accepted):
n,m = list(map(int,input().split()))
s = []
c = []
for i in range(m):
    ss,cc = list(map(int,input().split()))
    s.append(ss -1 )
    c.append(cc)

ans = [-1] * n
flag = True
for i in range(m):
    if ans[s[i]] == -1 :
        ans[s[i]] = c[i]
    elif ans[s[i]] != c[i]:
        flag = False

if n !=1 and  ans[0] == 0:
    flag = False

if flag :
    ans = [ str(a) if a != -1 else "0" for a in ans ]
    if n != 1 and ans[0] == "0":
        ans[0] = "1"
    print("".join(ans))
else:
    print(-1)
Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
num = {}
fin = True
for i in range(m):
    s, c = map(int, input().split())
    if s not in num:
        num[s] = c
    elif s in num and num[s] != c:
        fin = False
        break
    else:
        pass

if fin:
    num2 = [0] * n
    for j in num.keys():
        num2[j - 1] = num[j]
    if num2[0] == 0:
        print(-1)
        exit()
    else:
        print(int("".join(map(str, num2))))

else:
    print(-1)


Failing test case input:
3 1
0 0
1 0

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
num = ["A"] * n
for i in range(m):
    s, c = map(int, input().split())
    if n>1 and s == 1 and c == 0:
        print(-1)
        exit()
    elif num[s - 1] != "A" and num[s - 1] != c:
        print(-1)
        exit()
    num[s - 1] = c

for j in range(n):
    if num[j] == "A":
        num[j] = 0
    if n>1 and num[0] == 0:
        num[0] = 1
print(int("".join(map(str, num))))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
SC = []
for i in range(M):
    SC.append(list(map(int, input().split())))
flag = 0
N, M = 3, 1
SC = [[1, 0]]
a = ""
A = [[] for row in range(N)]
for i, S in enumerate(SC):
    if not (str(S[1]) in A[S[0]-1]):
        A[S[0]-1].append(str(S[1]))
for i in range(0,N):
    if len(A[i]) == 0:
        if i == 0:
            a += "1"
        else:
            a += "0"
    elif i==0 and A[i][0] == "0":
        flag = 1
        break
    elif len(A[i]) == 1:
        a += A[i][0]
    else:
        flag = 1
        break

if flag == 1:
    print(-1)
else:
    print(int(a))

Failing test case input:
3 2
1 2
0 1

Expected output:
201


Actual output:
-1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
SC = []
for i in range(M):
    SC.append(list(map(int, input().split())))
flag = 0
a = ""
A = [[] for row in range(N)]
for i, S in enumerate(SC):
    if not (str(S[1]) in A[S[0]-1]):
        A[S[0]-1].append(str(S[1]))
for i in range(0,N):
    if len(A[i]) == 0:
        if i == 0 and N>1:
            a += "1"
        else:
            a += "0"
    elif i==0 and A[i][0] == "0"  and N>1:
        flag = 1
        break
    elif len(A[i]) == 1:
        a += A[i][0]
    else:
        flag = 1
        break

if flag == 1:
    print(-1)
else:
    print(int(a))
Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1:
        a[s]=c
    else:
        if a[s]!=c:
            print(-1)
            exit()
if n>=2 and a[0]==0:
    print(-1)
    exit()
ans=""
for i in range(n):
    if a[i]==-1:
        if i==0:
            ans+="1"
        else:
            ans+="0"
    else:
        ans+=str(a[i])
print(int(ans))


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1:
        a[s]=c
    else:
        if a[s]!=c:
            print(-1)
            exit()
if n==1:
    print(max(0,a[0]))
    exit()

if a[0]==0:
    print(-1)
    exit()

ans=""
for i in range(n):
    if a[i]==-1:
        if i==0:
            ans+="1"
        else:
            ans+="0"
    else:
        ans+=str(a[i])
print(ans)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M= [int(i) for i in input().split()]
SCm =[[int(i) for i in input().split()] for _ in range(M)]

results = [-1 for _ in range(N)]
impossible = False
for sc in SCm:
  s, c = sc
  if results[s-1] != -1:
    if results[s-1] != c:
      impossible =True
      break
  else:
    results[s-1] = c
if results[0] == 0:
  impossible = True
if impossible:
  print(-1)
else:
  results[0] = max(results[0], 1)
  print(int("".join([str(s if s >=0 else 0) for s in results])))



Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N, M= [int(i) for i in input().split()]
SCm =[[int(i) for i in input().split()] for _ in range(M)]

results = [-1 for _ in range(N)]
impossible = False
for sc in SCm:
  s, c = sc
  if results[s-1] != -1:
    if results[s-1] != c:
      impossible =True
      break
  else:
    results[s-1] = c
if (N > 1) and (results[0] == 0):
  impossible = True
if impossible:
  print(-1)
else:
  if N > 1:
    results[0] = max(results[0], 1)
  print(int("".join([str(s if s >=0 else 0) for s in results])))
Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    return -1
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==m:
      return i
    
  return -1

print(func(n, m, s_li_, c_li_))

Failing test case input:
3 0
2 0
2 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    if n==1:
      return 0
    else:
      return 10**(n-1)
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==m:
      return i
    
  return -1

print(func(n, m, s_li_, c_li_))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = list(map(int, input().split(' ')))
pairs = []

for i in range(m):
    pairs.append(list(map(int, input().split(' '))))

num = [-1 for i in range(n)]

for pair in pairs:
    s, c = pair

    if (num[s-1] != -1 and num[s-1] != c) or (s == 1 and c == 0):
        print(-1)
        exit(0)
    else:
        num[s-1] = c

for i in range(n):
    if num[i] == -1:
        num[i] = 0 if i != 0 else 1

print(''.join([str(i) for i in num]))


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n, m = list(map(int, input().split(' ')))
pairs = []

for i in range(m):
    pairs.append(list(map(int, input().split(' '))))

num = [-1 for i in range(n)]

for pair in pairs:
    s, c = pair

    if (num[s-1] != -1 and num[s-1] != c) or (s == 1 and c == 0 and n > 1):
        print(-1)
        exit(0)
    else:
        num[s-1] = c

for i in range(n):
    if num[i] == -1:
        num[i] = 0 if i != 0 or n == 1 else 1

print(''.join([str(i) for i in num]))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())

t = [None] * n
invalid = False

for _ in range(m):
    s, c = map(int, input().split())
    if t[s-1] is None or t[s-1] == c:
        t[s-1] = c
    else:
        invalid = True

for i in range(n):
    if t[i] is None:
        t[i] = 0

if invalid:
    print(-1)
else:
    if t[0] == 0 and n > 1:
        print(-1)
    else:
        v = 0
        for i in range(n):
            v += t[-1 - i] * 10 ** i
        print(v)


Failing test case input:
3 1
0 1
1 0

Expected output:
101


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())

t = [None] * n
invalid = False

for _ in range(m):
    s, c = map(int, input().split())
    if t[s-1] is None or t[s-1] == c:
        t[s-1] = c
    else:
        invalid = True

for i in range(n):
    if t[i] is None:
        if i == 0 and n > 1:
            t[i] = 1
        else:
            t[i] = 0

if invalid:
    print(-1)
else:
    if t[0] == 0 and n > 1:
        print(-1)
    else:
        v = 0
        for i in range(n):
            v += t[-1 - i] * 10 ** i
        print(v)

Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M = map(int, input().split())
A=[]
for j in range(M):
    s, c = map(int, input().split())
    A.append([s-1, str(c)])

ans=[]
for i in range(1, 999):
    a = 0
    for j in range(M):
        x=str(i)
        if len(x) < N:
            break 
        if A[j][1] == x[A[j][0]]:
            a += 1
    if a == M:
        ans.append(i)
if ans == []:
    print(-1)
else:
    print(min(ans))

Failing test case input:
3 0
2 1
2 2

Expected output:
100


Actual output:
1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
A=[]
for j in range(M):
    s, c = map(int, input().split())
    A.append([s-1, str(c)])
if N == 1:
    b = 0
elif N == 2:
    b= 10
else:
    b = 100
ans=[]
for i in range(b, 1000):
    a = 0
    for j in range(M):
        x=str(i)
        if len(x) < N:
            break 
        if A[j][1] == x[A[j][0]]:
            a += 1
    if a == M:
        ans.append(i)
if ans == []:
    print(-1)
else:
    print(min(ans))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    digit = si - 1
    if answer[digit] is not None and answer[digit] != ci:
        print('-1')
        exit()
    
    answer[digit] = ci

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

if answer[0] == 0 and N != 1:
    print('-1')
    exit()

answer = int(''.join(map(str, answer)))
print(answer)


Failing test case input:
3 1
2 0
1 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    digit = si - 1
    if answer[digit] is not None and answer[digit] != ci:
    
        print('-1')
        exit()
    
    answer[digit] = ci

if answer[0] == 0 and N != 1:
    print('-1')
    exit()

if answer[0] is None and N == 1:
    answer[0] = 0
elif answer[0] is None:
    answer[0] = 1

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

answer = int(''.join(map(str, answer)))
print(answer)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m = mi()

    ans = [None] *n

    for i in range(m):
        s,c = mi()
        if((ans[s-1] == c) or (ans[s-1] == None)):
            ans[s-1] = c
        else:
            print('-1')
            return

    if(ans[0] == 0):
        if(len(ans) == 1):
            print(0)
            return
        else:
            print('-1')
            return

    
    ans2 = 0
    dec = 1
    for i in range(n-1,-1,-1):
        if(ans[i] == None):
            if(i == 0):
                ans[i] = 1
            else:
                ans[i] = 0
        ans2 += ans[i] * dec
        dec *= 10

    print(ans2)

if __name__ == "__main__":
    main()

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m = mi()

    ans = [None] *n

    for i in range(m):
        s,c = mi()
        if((ans[s-1] == c) or (ans[s-1] == None)):
            ans[s-1] = c
        else:
            print('-1')
            return

    if(ans[0] == 0):
        if(len(ans) == 1):
            print(0)
            return
        else:
            print('-1')
            return

    if(len(ans) == 1):
        if(ans[0] == None):
            print(0)
            return
    ans2 = 0
    dec = 1
    for i in range(n-1,-1,-1):
        if(ans[i] == None):
            if(i == 0):
                ans[i] = 1
            else:
                ans[i] = 0
        ans2 += ans[i] * dec
        dec *= 10

    print(ans2)

if __name__ == "__main__":
    main()
Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
N, M = map(int, input().split())

a = [-1]*N

for _ in range(M):
    s, c = map(int, input().split())
    if a[s-1] != -1 and a[s-1] != c:
        print('-1')
        sys.exit()
    else:
        a[s-1] = c

a = ['0' if x == -1 else str(x) for x in a]
if all([x == '0' for x in a]):
    print('0')
elif a[0] == '0':
    print('-1')
else:
    print(''.join(a))


Failing test case input:
3 2
-1 3
0 1

Expected output:
131


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys

n, m = map(int, input().split())
num = [-1]*n

for i in range(m):
  s,c = map(int, input().split())
  if num[s-1] != -1 and num[s-1] != c:
      print(-1)
      sys.exit()
  num[s-1] = c
  
if n == 1 and num[0] == -1:
    num[0] = 0
elif n != 1 and num[0] == -1:
    num[0] = 1

num = ['0' if x == -1 else str(x) for x in num]

if len(str(int(''.join(num)))) == n:
    print(''.join(num))
else:
    print(-1)

Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1:
        a[s]=c
    else:
        if a[s]!=c:
            print(-1)
            exit()
if n==1:
    print(a[0])
    exit()

if a[0]==0:
    print(-1)
    exit()

ans=""
for i in range(n):
    if a[i]==-1:
        if i==0:
            ans+="1"
        else:
            ans+="0"
    else:
        ans+=str(a[i])
print(ans)


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1:
        a[s]=c
    else:
        if a[s]!=c:
            print(-1)
            exit()
if n==1:
    print(max(0,a[0]))
    exit()

if a[0]==0:
    print(-1)
    exit()

ans=""
for i in range(n):
    if a[i]==-1:
        if i==0:
            ans+="1"
        else:
            ans+="0"
    else:
        ans+=str(a[i])
print(ans)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())

score=[-1]*N

for i in range(M):
    s,c=map(int,input().split())
    s-=1

    if score[s]==-1 or score[s]==c:
        score[s]=c
    else:
        print(-1)
        sys.exit()
    
if score[0]==0:
    print(-1)
    sys.exit()

for i in range(N):
    if score[i]==-1:
        score[i]=0

if max(score)==0:
    score[0]=1

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


Failing test case input:
3 2
3 0
2 6

Expected output:
160


Actual output:
060


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

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


for i in range(1000):
    S=str(i)

    if len(S)==N:
        for s,c in C:
            s-=1
            if S[s]==str(c):
                True
            else:
                break
        else:
            print(i)
            sys.exit()

print(-1)
Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(M)]
ans = ["0"]*N
f = [False]*N
for s, c in sc:
    s -= 1
    c = str(c)
    if f[s] and ans[s] != c:
        break
    f[s] = True
    ans[s] = c
else:
    if not(N != 1 and ans[0] == '0'):
        print(''.join(ans))
        exit()
print(-1)


Failing test case input:
3 1
2 0
1 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
N, M = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(M)]
ans = ["0"]*N
f = [False]*N
for s, c in sc:
    s -= 1
    c = str(c)
    if (f[s] and ans[s] != c)or(N > 1 and s == 0 and c == '0'):
        break
    f[s] = True
    ans[s] = c
else:
    if not(N != 1 and ans[0] == '0'):
        print(''.join(ans))
    else:
        ans[0] = '1'
        print(''.join(ans))
    exit()

print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int, input().split())
d = ['x']*N

flg = 0
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if d[s] == 'x':
    d[s] = c
  if d[s] != c or (s==0 and c==0 and N>1):
    flg = -1

ans = 0
for j in range(N):
  N-=1
  if d[j]=='x':
    if j == 0:
      d[j] = 1
    else:
      d[j] = 0
  ans += d[j]*(10**N)

print(flg if flg == -1 else ans)

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = map(int, input().split())
d = ['x']*N

flg = 0
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if d[s] == 'x':
    d[s] = c
  if d[s] != c or (s==0 and c==0 and N>1):
    flg = -1

ans = 0
for j in range(N):
  N-=1
  if d[j]=='x':
    if j == 0 and N>0:
      d[j] = 1
    else:
      d[j] = 0
  ans += d[j]*(10**N)

print(flg if flg == -1 else ans)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n, m = list(map(int, input().split()))
res = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]

for r in res:
	if ans[r[0] - 1] >= 0:
		if ans[r[0] - 1] != r[1]:
			print(-1)
			sys.exit()
	ans[r[0] - 1] = r[1]

flag = 0
for i in range(n):
	if ans[i] == -1:
		if flag:
			ans[i] = 0
		else:
			ans[i] = 1
	if i == 0 and ans[i] == 0:
		print(-1)
		sys.exit()
	else:
		flag = 1


print("".join([str(a) for a in ans]))

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
n, m = list(map(int, input().split()))
res = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]



if n == 1:
	tmp = 0
	for i in range(m):
		tmp += res[i][1]
	if tmp == 0:
		print(0)
		sys.exit()

for r in res:
	if ans[r[0] - 1] >= 0:
		if ans[r[0] - 1] != r[1]:
			print(-1)
			sys.exit()
	ans[r[0] - 1] = r[1]



flag = 0
for i in range(n):
	if ans[i] == -1:
		if flag:
			ans[i] = 0
		else:
			ans[i] = 1
	if i == 0 and ans[i] == 0:
		print(-1)
		sys.exit()
	else:
		flag = 1


print("".join([str(a) for a in ans]))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
a = []
for i in range(m):
	s,c = map(int, input().split())
	a.append([s,c])

for i in range(10**(n-1),10**n):
	if all(str(i)[s-1] == str(c) for s,c in a):
		print (i)
		exit()
print (-1)

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


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

for i in range(10**(n-1)-1,10**n):
	if len(str(i)) != n:
		continue
	if all(str(i)[s-1] == str(c) for s,c in a):
		print (i)
		exit()
print (-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N, M = map(int, input().split())

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

if (1, 0) in c:
    print(-1)
else:
    ans = -1

    
    for i in range(100, 1000):
        str_i = str(i)
        if False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
            ans = i
            break

    print(ans)

Failing test case input:
2 1
1 3
2 0

Expected output:
30


Actual output:
300


Fixed submission (verdict: Accepted):

N, M = map(int, input().split())

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

ans = -1


for i in range(1000):
    str_i = str(i)

    if N < len(str_i):
        break

    if N == len(str_i) and False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
        ans = i
        break

print(ans)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
if n==1:
  for i in range(10):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
else:
  for i in range(10**(n-1),10**n):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break

Failing test case input:
3 2
1 0
1 3

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
if n==1:
  for i in range(10):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)
else:
  for i in range(10**(n-1),10**n):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)
Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M = map(int,input().split())


number = [0 for _ in range(N)] 

for i in range(M):
    s,c = map(int,input().split())

    if number[s-1] == 0 or number[s-1] == c:
        number[s-1] = c
    else:
        
        print(-1)
        exit()


if N == 1 and number[0] == 0:
    print(0)
    exit()

if number[0] == 0:
    print(-1)
    exit()

if N == 2:
    print(number[0]*10+number[1])
    exit()
if N == 3:
    print(number[0]*100+number[1]*10+number[2])
    exit()


Failing test case input:
3 1
2 1
1 3

Expected output:
110


Actual output:
-1


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


number = [-1 for _ in range(N)] 

for i in range(M):
    s,c = map(int,input().split())

    if number[s-1] == -1 or number[s-1] == c:
        number[s-1] = c
    else:
        
        print(-1)
        exit()


if N == 1:
    if number[0] == -1:
        print(0)
    else:
        print(number[0])
    exit()


if number[0] == 0:
    print(-1)
    exit()


if number[0] == -1:
    number[0] = 1    
for i in range(1,N):
    if number[i] == -1:
        number[i] = 0

if N == 2:
    print(number[0]*10+number[1])
    exit()
if N == 3:
    print(number[0]*100+number[1]*10+number[2])
    exit()

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = list(map(int, input().split(' ')))

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

false_flag = False

for i in range(M):
    s, c = list(map(int, input().split(' ')))

    if num_list[s-1] != -1:
        if num_list[s-1] == c:
            continue
        else:
            false_flag = True
            break
    else:
        num_list[s-1] = c
if num_list[0] == 0:
    false_flag = True

if false_flag == False:
    for i in range(N):
        if num_list[i] == -1:
            num_list[i] = 0
    print(*num_list, sep='')
else:
    print(-1)

Failing test case input:
3 1
0 1
1 1

Expected output:
101


Actual output:
001


Fixed submission (verdict: Accepted):
N, M = list(map(int, input().split(' ')))

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

false_flag = False

sc = []
for i in range(M):
    sc.append(list(map(int, input().split(' '))))

for i in range(M):
    s, c = sc[i][0], sc[i][1]

    if num_list[s-1] == -1:
        num_list[s-1] = c
    else:
        if num_list[s-1] == c:
            pass
        else:
            false_flag = True
if num_list[0] == 0:
    if N > 1:
        false_flag = True

if false_flag == False:
    for i in range(N):
        if num_list[i] == -1:
            if i == 0:
                if N > 1:
                    num_list[0] = 1
                else:
                    num_list[0] = 0
            else:
                num_list[i] = 0
    print(*num_list, sep='')
else:
    print(-1)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

import sys

number = [0]*N
n_count = [0]*N

for i in range(M):
    
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1] = sc[i][1]
    n_count[sc[i][0]-1] += 1

if number[0] == 0:
    print(-1)
    sys.exit()
    
for i in range(N):
    print(number[i],end='')

Failing test case input:
3 0
0 0
2 3

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

import sys

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
 
number = [[i for i in range(10)] for i in range(N)]
number[0].pop(0)

n_count = [0]*N
 
for i in range(M):
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1][-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1].append(sc[i][1])
    n_count[sc[i][0]-1] += 1
    
if N != 1 and number[0][-1] == 0:
    print(-1)
    sys.exit()

for i in range(N):
    if n_count[i] > 0:
        print(number[i][-1],end='')
    else:
        print(min(number[i]),end='')

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for i in range(M)]

start = 10**(N-1)
end = 10**N

for n in range(start,end):
    n = str(n)
    b = True
    for s,c in SC:
        if n[s-1] != str(c):
            b = False
            break
    if b:
        print(n)
        break
if not b:
    print(-1)


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for i in range(M)]

for n in range(1000):
    n = str(n)
    if len(n) != N:
        continue
    b = True
    for s,c in SC:
        if n[s-1] != str(c):
            b = False
            break
    if b:
        print(n)
        break
if not b:
    print(-1)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n,m=list(map(int,input().split()))
ans=[-1 for i in range(n)]
num=0
for i in range(m):
  s,c=list(map(int,input().split()))
  if n==1 and c==0:
    print(0)
    sys.exit()
  if s==1 and c==0:
    print(-1)
    sys.exit()
  if ans[s-1]==-1 or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    sys.exit()

  sys.exit()
if ans[0]==-1:
  ans[0]=1
for i in range(1,n):
  if ans[i]==-1:
    ans[i]=0
ans=map(str, ans)
print("".join(ans))

  

Failing test case input:
3 2
2 1
1 3

Expected output:
310


Actual output:

Fixed submission (verdict: Accepted):
import sys
n,m=list(map(int,input().split()))
ans=[-1 for i in range(n)]

for i in range(m):
  s,c=list(map(int,input().split()))
  if n!=1 and s==1 and c==0:
    print(-1)
    sys.exit()
  if ans[s-1]==-1 or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    sys.exit()

    
if n==1 and (ans[0]==0 or ans[0]==-1):
  print(0)
  sys.exit()
if ans[0]==-1:
  ans[0]=1
for i in range(1,n):
  if ans[i]==-1:
    ans[i]=0
ans=map(str, ans)
print("".join(ans))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
A = ['0']*N
for i in range(M):
  s,c = list(map(int,input().split()))
  if A[s-1] != '0' and A[s-1] != str(c):
    print('-1')
    exit()
  else:
    A[s-1] = str(c)
if len(A) != 1 and A[0] == '0':
    print('-1')
    exit()
print(''.join(A))

Failing test case input:
3 1
2 0
1 7

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
A = ['a']*N
for i in range(M):
  s,c = list(map(int,input().split()))
  if A[s-1] != 'a' and A[s-1] != str(c):
    print('-1')
    exit()
  else:
    A[s-1] = str(c)
if A[0] == '0' and len(A) != 1:
  print('-1')
  exit()
elif A[0] == 'a' and len(A) != 1:
  A[0] = '1'
for i in range(N):
      if A[i] == 'a':
        A[i] = '0'
print(''.join(A))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())

d = {}
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if s not in d or d[s] == c:
        d[s] = c
    else:
        print(-1)
        exit()

for i in range(10**(n-1), 10**n):
    i = str(i)
    if all(i[s] == c for s, c in d.items()):
        print(i)
        exit()

Failing test case input:
3 1
1 0
0 1

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n, m = map(int, input().split())

ans = [0]*n
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if ans[s] == 0 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()
if n > 1 and ans[0] == '0':
    print(-1)
    exit()
if n > 1 and ans[0] == 0:
    ans[0] = '1'
print(*ans, sep='')