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

sc.sort()

hantei = [-1] * n
for i in range(m):
    if hantei[sc[i][0] - 1] == -1 or hantei[sc[i][0] - 1] == sc[i][1]:
        hantei[sc[i][0] - 1] = sc[i][1]
    else:
        print("-1")
        exit()

leng = len(hantei)
for i in range(leng):
    if i == 0 and hantei[i] == 0:
        print("-1")
        exit()
    else:
        if hantei[i] != -1:
            print(hantei[i], end="")
        else:
            if i != 0:
                print("0", end="")
            else:
                print("1", end="")

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, list(input().split()))) for i in range(m)]

sc.sort()

hantei = [-1] * n
for i in range(m):
    if hantei[sc[i][0] - 1] == -1 or hantei[sc[i][0] - 1] == sc[i][1]:
        hantei[sc[i][0] - 1] = sc[i][1]
    else:
        print("-1")
        exit()

leng = len(hantei)
for i in range(leng):
    if i == 0 and hantei[i] == 0 and leng != 1:
        print("-1")
        exit()
    else:
        if hantei[i] != -1:
            print(hantei[i], end="")
        else:
            if i != 0:
                print("0", end="")
            elif leng == 1:
                print("0")
            else:
                print("1", end="")

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, M = map(int, input().split())
    S = []
    for i in range(M):
        S.append(tuple(map(int, input().split())))

    for i in range(1 * (10**(N-1)), 10**N):
        k = str(i)
        count = 0
        for s, c in S:
            if k[s-1] == str(c):
                count += 1
        if count == M:
            print(i)
            return 0
    print(-1)

    return 0


if __name__ == '__main__':
    main()

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def main():
    N, M = map(int, input().split())
    S = []
    for _ in range(M):
        S.append(tuple(map(int, input().split())))

    for i in range(0, 10**N):
        k = str(i)
        count = 0
        if len(k) < N:
            continue
        for s, c in S:
            if k[s-1] == str(c):
                count += 1
        if count == M:
            print(i)
            return 0
    print(-1)

    return 0


if __name__ == '__main__':
    main()
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1] * n

for s, c in sc:
    t = s - 1
    if ans[t] == -1:
        ans[t] = c
    elif ans[t] != c:
        print(-1)
        exit()

if ans[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit()
ans[0] = str(max(1, ans[0]))
for i in range(1, n):
    ans[i] = str(max(0, ans[i]))

print(''.join(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())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1] * n

for s, c in sc:
    t = s - 1
    if ans[t] == -1:
        ans[t] = c
    elif ans[t] != c:
        print(-1)
        exit()

if n == 1:
    if ans[0] == -1:
        ans[0] = '0'
    else:
        ans[0] = str(ans[0])
elif ans[0] == 0:
    print(-1)
    exit()
else:
    ans[0] = str(max(1, ans[0]))
for i in range(1, n):
    ans[i] = str(max(0, ans[i]))

print(''.join(ans))

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    if M == 0:
        print(10**(N-1))
    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()


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
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()
Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

N, M = map(int, input().split())
num = [-1]*N

for _ in range(M):
    a, b = map(int, input().split())
    if N == 1:
        print(b)
        sys.exit()
    elif num[a-1] == -1 or num[a-1] == b:
        num[a-1] = b
    else:
        num[a-1] = False

if False in num:
    print(-1)
else:
    num = ['0' if x == -1 else str(x) for x in num]
    if num[0] == '0':
        print(-1)
    else:
        print(''.join(num))


Failing test case input:
3 2
2 0
1 3

Expected output:
300


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):
n, m = map(int,input().split())
ans = 0
a = [-1]*n
for i in range(m):
  s, c = map(int,input().split())
  if a[s-1] in [-1, c]:
    a[s-1] = c
  else:
    ans = -1
    break
if a[0] == 0:
  ans = -1
if ans == 0:
  ans += max(a[0],1)*10**(n-1)
  for i in range(1,n):
    ans += max(a[i],0)*10**(n-i-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
a = [-1]*n
for i in range(m):
  s, c = map(int,input().split())
  if a[s-1] in [-1, c]:
    a[s-1] = c
  else:
    ans = -1
    break
if a[0] == 0 and n > 1:
  ans = -1
if ans == 0 and a != [0] and a != [-1]:
  ans += max(a[0],1)*10**(n-1)
  for i in range(1,n):
    ans += max(a[i],0)*10**(n-i-1)
print(ans)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = (int(x) for x in input().split())
num = [-10]*N

ans = True

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

    if num[s-1] == -10 or num[s-1] == c:
        num[s-1] = c
    else:
        ans = False
        break
if num[0] == -10:
    num[0] = 1
    
for i in range(1,N):
    if num[i] == -10:
        num[i] = 0
if N != 1:
    if num[0] == 0:
        ans = False

if ans:
    for s in num:
        print(s,end='')

    print()

else:
    print(-1)



Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = (int(x) for x in input().split())
num = [-10]*N

ans = True

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

    if num[s-1] == -10 or num[s-1] == c:
        num[s-1] = c
    else:
        ans = False
        break


if num[0] == -10:
    if N != 1:
        num[0] = 1
    else:
        num[0] = 0
        
for i in range(1,N):
    if num[i] == -10:
        num[i] = 0
        
if N != 1:
    if num[0] == 0:
        ans = False

if ans:
    for s in num:
        print(s,end='')

    print()

else:
    print(-1)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
ans=["a"]*n
for i in range(0,m):
  s,c=map(int,input().split())
  if ans[s-1]=="a" or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    break
else:
  for i in range(0,n):
    if ans[i]=="a":
      ans[i]=0
  if ans[0]==0:
    print(-1)
  else:
    if n==3:
      ans=int(ans[0])*100+int(ans[1])*10+int(ans[2])
    elif n==2:
      ans=int(ans[0])*10+int(ans[1])
    else:
      ans=int(ans[0])
    print(ans)

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

Expected output:
112


Actual output:
-1


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
ans=["a"]*n
for i in range(0,m):
  s,c=map(int,input().split())
  if ans[s-1]=="a" or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    break
else:
  if n==1 and ans[0]=="a":
    ans[0]=0
  elif ans[0]=="a":
    ans[0]=1
  for i in range(0,n):
    if ans[i]=="a":
      ans[i]=0
  if i>=2 and ans[0]==0:
    print(-1)
  else:
    if n==3:
      ans=int(ans[0])*100+int(ans[1])*10+int(ans[2])
    elif n==2:
      ans=int(ans[0])*10+int(ans[1])
    else:
      ans=int(ans[0])
    print(ans)

Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(3)]
visited=[[] for i in range(3)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if S[0]==0:
    print(-1)
    sys.exit()
if S[0]==-1:
    S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

Failing test case input:
2 1
0 2
1 0

Expected output:
12


Actual output:
102


Fixed submission (verdict: Accepted):
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1:
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

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

ans = [-1] * N

for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

if M == 0 and N != 1:
    ans[0] = 1
ans = [int(str(a).replace('-1', '0')) for a in ans]
res = ''.join((map(str, ans)))
if int(res) >= 0 and len(str(int(res))) == N:
    print(int(res))
else:
    print(-1)


Failing test case input:
3 1
2 0
0 1

Expected output:
100


Actual output:
-1


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

ans = [-1] * N

for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

if M == 0 and N != 1:
    ans[0] = 1
tmp = int(''.join((map(str, [int(str(a).replace('-1', '0')) for a in ans]))))
if N >= 2 and ans[0] == -1:
    ans[0] = 1

ans = [int(str(a).replace('-1', '0')) for a in ans]

res = ''.join((map(str, ans)))
if int(res) >= 0 and len(str(int(res))) == N:
    print(int(res))
else:
    print(-1)

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

keta = [10]*N
ans = 0
for i in range(M):
  keta[s[i]-1] = min(keta[s[i]-1], c[i])

for i in range(N):
  if (keta[0] == 10 and N != 1) or (keta[0] == 0 and N != 1):
    print(-1)
    exit()
  elif keta[i] != 10:
    ans += keta[i]*pow(10,N-i-1)
print(ans)

Failing test case input:
3 1
2 2
1 0

Expected output:
120


Actual output:
-1


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
s, c = [0]*M, [0]*M
for i in range(M):
  s[i], c[i] = map(int,input().split())

keta = [10]*N
for i in range(M):
  if keta[s[i]-1] == 10:
    keta[s[i]-1] = c[i]
  else:
    if keta[s[i]-1] != c[i]:
      print(-1)
      exit()
ans = 0
for i in range(N):
  if keta[0] == 0 and N != 1:
    print(-1)
    exit()
  elif i == 0 and keta[0] == 10:
    if N != 1:
      ans += pow(10,N-1)
    else:
      ans = 0
  elif keta[i] != 10:
    ans += keta[i]*pow(10,N-i-1)
print(ans)
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)]

sc = sorted(sc, key= lambda x: x[0])
ans = [0] * N

check = [-1] * N
for i in sc:
    if N == 3 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if N == 2 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()

    if check[i[0]-1] == -1:
        check[i[0]-1] = i[1]
    elif check[i[0]-1] != i[1]:
        print(-1)
        exit()


for i in sc:
    ans[i[0] - 1] = i[1]
for i in ans:
    print(i, end="")

Failing test case input:
3 1
2 1
1 3

Expected output:
110


Actual output:
010

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

sc = sorted(sc, key= lambda x: x[0])
ans = [0] * N

check = [-1] * N
for i in sc:
    if N == 3 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if N == 2 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if check[i[0]-1] == -1:
        check[i[0]-1] = i[1]
    elif check[i[0]-1] != i[1]:
        print(-1)
        exit()


for i in sc:
    ans[i[0] - 1] = i[1]

if len(ans) == 3 and ans[0] == 0:
    ans[0] = 1
if len(ans) == 2 and ans[0] == 0:
    ans[0] = 1
for i in ans:
    print(i, end="")

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
cnt = -1
man = False
for n in range(1000):
    num = str(n)
    res = True
    for m in range(M):
        if S[m] > N or len(num) != N:
            res = False
            continue
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)

Failing test case input:
3 0
0 0
2 3

Expected output:
100


Actual output:
0


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
cnt = -1
man = False
for n in range(1000):
    num = str(n)
    res = True
    if len(num) != N:
        res = False
        continue
    for m in range(M):
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin

def main():
    input = stdin.readline

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

    s = [0] * M
    c = [0] * M

    ans = [None] * N
    for i in range(M):
        s[i], c[i] = map(int, input().split())

        if(ans[s[i]-1] is None):
            ans[s[i]-1] = c[i]
        elif(ans[s[i]-1] == c[i]):
            continue
        else:
            print("-1")
            return
    
    for i in range(N):
        if(ans[i] is None):
            ans[i] = 0
    
    ans_num = int(''.join(map(str,ans)))

    if(ans_num == 0)&(N > 1):
        print(-1)
    else:
        print(ans_num)

if __name__ == "__main__":
    main()

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

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
from sys import stdin

def main():
    input = stdin.readline

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

    s = [0] * M
    c = [0] * M

    ans = [None] * N
    for i in range(M):
        s[i], c[i] = map(int, input().split())

        if(ans[s[i]-1] is None):
            ans[s[i]-1] = c[i]
        elif(ans[s[i]-1] == c[i]):
            continue
        else:
            print("-1")
            return
    
    if(ans[0] is None)&(N > 1):
        ans[0] = 1
    elif(ans[0] is None)&(N==0):
        ans[0] = 0

    for i in range(N):
        if(ans[i] is None):
            ans[i] = 0
    
    ans_num = int(''.join(map(str,ans)))

    if(ans_num == 0)&(N > 1):
        print(-1)
    else:
        print(ans_num)

if __name__ == "__main__":
    main()

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

if f==1:
  print(-1)
else:
  if ans[0]=="-1":
    ans[0]="1"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)

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=["-1"]*N
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0 and N!=1:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  if ans[0]=="-1" and N!=1:
    ans[0]="1"
  elif M==0 and N==1:
    ans[0]="0"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    result = ['*'] * N
    for i in range(M):
        s, c = [int(x) for x in stdin.readline().rstrip().split()]
        if result[s - 1] == '*' or result[s - 1] == str(c):
            result[s - 1] = str(c)
        else:
            print(-1)
            return
    if result[0] == '0' and N != 1:
        print(-1)
        return
    if result[0] == '*':
        result[0] = '1'
    for i, x in enumerate(result):
        if x == '*':
            result[i] = '0'
    print(''.join(result))


if __name__ == "__main__":
    main()


Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    result = ['*'] * N
    for i in range(M):
        s, c = [int(x) for x in stdin.readline().rstrip().split()]
        if result[s - 1] == '*' or result[s - 1] == str(c):
            result[s - 1] = str(c)
        else:
            print(-1)
            return
    if result[0] == '0' and N != 1:
        print(-1)
        return
    if result[0] == '*' and N == 1:
        result[0] = '0'
    if result[0] == '*':
        result[0] = '1'
    for i in range(N):
        if result[i] == '*':
            result[i] = '0'
    print(''.join(result))


if __name__ == "__main__":
    main()

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

ans = [-1] * N
if N == 1 and M == 0:
    print(-1)
    exit(0)
for _ in range(M):
    sn, cn = map(int, input().split())
    if ans[sn - 1] != -1 and ans[sn - 1] != cn:
        print(-1)
        exit(0)
    if sn == 1 and cn == 0 and N > 1:
        print(-1)
        exit(0)
    ans[sn - 1] = cn
if ans[0] == -1:
    ans[0] = 1
ans = list(map(lambda x: str(0) if x == -1 else str(x), ans))
print("".join(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 = [-1] * N
if N == 1 and M == 0:
    print(0)
    exit(0)
for _ in range(M):
    sn, cn = map(int, input().split())
    if ans[sn - 1] != -1 and ans[sn - 1] != cn:
        print(-1)
        exit(0)
    if sn == 1 and cn == 0 and N > 1:
        print(-1)
        exit(0)
    ans[sn - 1] = cn
if ans[0] == -1:
    ans[0] = 1
ans = list(map(lambda x: str(0) if x == -1 else str(x), ans))
print("".join(ans))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
SC = [tuple(map(int,input().split())) for i in range(M)]

ans = [None] * N
for s,c in SC:
    s -= 1
    if ans[s] is None or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()
if N > 1 and ans[0] == 0:
    print(-1)
    exit()


print(''.join(map(lambda x:str(x) if x else '0', ans)))

Failing test case input:
3 0
2 1
2 3

Expected output:
100


Actual output:
000


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

if N==1:
    r = range(0,10)
elif N==2:
    r = range(10,100)
else:
    r = range(100,1000)

for n in r:
    n = str(n)
    for s,c in SC:
        s -= 1
        if n[s] != str(c):
            break
    else:
        print(n)
        exit()
print(-1)

Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    n,m = map(int, input().split())
    ans = [0] * n
    chg = [0] * n
    flg = 0
    for i in range(m):
        j,k = map(int, input().split())
        if chg[j-1] == 1 and ans[j-1] != k:
            flg = -1
        elif ans[j-1] == 0:
            ans[j-1] = k
            chg[j-1] = 1
    if flg == -1:
        print(flg)
    elif ans[0] == 0:
        print(-1)
    else:
        if n == 3:
            print(ans[0],ans[1],ans[2],sep="")
        elif n == 2:
            print(ans[0],ans[1],sep="")
        else:
            print(ans[0])


if __name__ == '__main__':
    main()
   

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

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
def main():
    n,m = map(int, input().split())
    ans = [0] * n
    chg = [0] * n
    flg = 0
    for i in range(m):
        j,k = map(int, input().split())
        if chg[j-1] == 1 and ans[j-1] != k:
            flg = -1
        elif ans[j-1] == 0:
            ans[j-1] = k
            chg[j-1] = 1
    if flg == -1:
        print(flg)
    elif len(ans) >= 2 and ans[0] == 0:
        if chg[0] == 0:
            ans[0] = 1
            if n == 3:
                print(ans[0], ans[1], ans[2], sep="")
            elif n == 2:
                print(ans[0], ans[1], sep="")
        else:
            print(-1)
    else:
        if n == 3:
            print(ans[0],ans[1],ans[2],sep="")
        elif n == 2:
            print(ans[0],ans[1],sep="")
        else:
            print(ans[0])


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

conditions = []
for _ in range(M):
    s, c = input().split(' ')
    conditions.append((int(s) - 1, c))

lowest = int('1' + '0' * (N - 1))
highest = int('1' + '0' * N)

for n in range(lowest, highest):
    sn = str(n)
    for s, c in conditions:
        if sn[s] != c:
            break
    else:
        print(sn)
        break
else:
    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(' '))

conditions = []
for _ in range(M):
    s, c = input().split(' ')
    conditions.append((int(s) - 1, c))


def check(n):
    sn = str(n)
    for s, c in conditions:
        if sn[s] != c:
            return False
    else:
        return True


if N == 1:
    lowest = 0
else:
    lowest = int('1' + '0' * (N - 1))
highest = int('1' + '0' * N)

for n in range(lowest, highest):
    if check(n):
        print(n)
        break
else:
    print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=[int(x) for x in input().rstrip().split()]
flag = 1
l=[-1 for i in range(n)]
for i in range(m):
    s,c = [int(x) for x in input().rstrip().split()]
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        flag =0
        break
        

ans = ""
if flag == 0 or (n!=1 and l[0]==0):
    print(-1)
else:
    for i in range(len(l)):
        if l[i]==-1:
            if i==0:
                ans+=str(1)
            else:
                ans+=str(0)
        else:
            ans+=str(l[i])
    print(ans)












Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,m=[int(x) for x in input().rstrip().split()]
flag = 1
l=[-1 for i in range(n)]
for i in range(m):
    s,c = [int(x) for x in input().rstrip().split()]
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        flag =0
        break
        

ans = ""
if flag == 0 or (n!=1 and l[0]==0):
    print(-1)
else:
    for i in range(len(l)):
        if l[i]==-1:
            if i==0 and n!=1:
                ans+=str(1)
            elif i==0 and n==1:
                ans+=str(0)
            else:
                ans+=str(0)
        else:
            ans+=str(l[i])
    print(ans)
Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
L=[-1]*n
for i in range(m):
  a,b=map(int,input().split())
  if L[a-1]!=-1:
    if L[a-1]!=b:
      print(-1)
      exit()
  else:
    L[a-1]=b
  if a==1 and b==0:
    print(-1)
    exit()
for i in range(len(L)):
  if L[i]==-1:
    L[i]=0
L=list(map(str,L))
k="".join(L)
k=int(k)
if k==0:
  print(10**(n-1))
else:
  print(k)

Failing test case input:
3 1
0 1
1 0

Expected output:
101


Actual output:
1


Fixed submission (verdict: Accepted):
A=list()
B=list()
n,m=map(int,input().split())
if m==0:
  print([0, 10, 100][n - 1])
  exit()
for i in range(m):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  if a==1 and b==0 and n!=1:
    print(-1)
    exit()
for i in range(1000):
  c=str(i)
  if len(c)==n:
    for j in range(m):
      if c[A[j]-1]!=str(B[j]):
        break
      if j==m-1:
        print(i)
        exit()
print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
l=[-1]*N
a=[]
for i in range(M):
    s,c=map(int,input().split())
    if l[s-1]!=c and l[s-1]!=-1:
        a=-1
        break
    l[s-1]=c
else:
    for i in range(N):
        if l[i]==-1 and i:
            a.append(0)
        elif l[i]==-1:
            a.append(1)
        else:
            a.append(l[i])
if a==-1:
    print(a)
elif a[0]==0 and N>1:
    print(-1)
else:
    print(*a,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())
l=[-1]*N
a=[]
for i in range(M):
    s,c=map(int,input().split())
    if l[s-1]!=c and l[s-1]!=-1:
        a=-1
        break
    l[s-1]=c
else:
    for i in range(N):
        if l[i]==-1 and i:
            a.append(0)
        elif l[i]==-1:
            if N>1:
                a.append(1)
            else:
                a.append(0)
        else:
            a.append(l[i])
if a==-1:
    print(a)
elif a[0]==0 and N>1:
    print(-1)
else:
    print(*a,sep="")
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
A = [1e9] * n
f = True
for _ in range(m):
    s, c = map(int, input().split())
    if A[s - 1] != 1e9:
        if A[s - 1] != c: 
            f = False
    if s - 1 == 0 and c == 0 and n != 1:
        f = False
    A[s - 1] = c

if f:
    ans = ""
    for i in range(len(A)):
        if i == 0 and A[i] == 1e9:
            ans += "1"
        else:
            if A[i] == 1e9:
                ans += "0"
            else:
                ans += str(A[i])
    print(int(ans))
else:
    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 = [1e9] * n
f = True
for _ in range(m):
    s, c = map(int, input().split())
    if A[s - 1] != 1e9:
        if A[s - 1] != c: 
            f = False
    if s - 1 == 0 and c == 0 and n != 1:
        f = False
    A[s - 1] = c

if f:
    ans = ""
    for i in range(len(A)):
        if i == 0 and A[i] == 1e9:
            if n == 1:
                ans += "0"
            else:
                ans += "1"
        else:
            if A[i] == 1e9:
                ans += "0"
            else:
                ans += str(A[i])
    print(int(ans))
else:
    print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
A = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if t == [1, 0] and N != 1:
    print(-1)
    exit()
  elif A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
B = [A[k] * (10 ** (N - 1 - k)) for k in range(N) if A[k] > 0]
print(sum(B))

Failing test case input:
3 2
0 1
2 2

Expected output:
121


Actual output:
21


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
A  = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
if N != 1 and A[0] == 0:
  print(-1)
  exit()
elif A.count(-1) == N and N != 1:
  print(1 * 10 ** (N - 1))
  exit()
elif A[0] == -1:
  if N == 1:
    A[0] = 0
  else:
    A[0] = 1
B = [A[j] * 10 ** (N - 1 - j) for j in range(N) if A[j] > 0]
print(sum(B))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
i = 0
l = [-1]*N
t = 0
while i<M:
    s,c = map(int,input().split())
    if s == 0 and c == 0:
        t = -1
    elif l[s-1] == -1 or l[s-1] == c:
        l[s-1] = c  
    else:
        t = -1 
    i+=1

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

if (l[0] == 0):
    l[0] = 1

if t == 0:
    for i in range(0,N):
        t += l[i]*(10**(N-i-1))
        i+=1

print(t)

Failing test case input:
3 1
1 0
1 3

Expected output:
-1


Actual output:
100


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
i = 0
l = [-1]*N
t = 0
while i<M:
    s,c = map(int,input().split())
    if N>1 and s == 1 and c == 0:
        t = -1
    elif l[s-1] == -1 or l[s-1] == c:
        l[s-1] = c  
    else:
        t = -1 
    i+=1

if N>1 and l[0] == -1:
    l[0] = 1
elif l[0] == -1:
    l[0] = 0

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

if t == 0:
    for i in range(0,N):
        t += l[i]*(10**(N-i-1))
        i+=1

print(t)

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


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

Expected output:
702

Actual output:
102


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
D=[-1]*N
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  if s==0 and c==0 and N>1: 
    print(-1)
    exit(0)
  if D[s]!=-1: 
    if D[s]!=c: 
      print(-1)
      exit(0)
  D[s]=c
  
ans=""
if D[0]==-1: 
  if N==1:
    print(0)
  else:
    ans+="1"
elif D[0]==0:
  if N==1:
    print(0)
    exit(0)
  else:
    ans+="1"
else:
  ans+=str(D[0])
  
for i in range(1,N):
  if D[i]==-1:
    ans+="0"
  else:
    ans+=str(D[i])
    
print(ans)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
if m == 0:
  print(-1)
  exit()
digit = [None] * n
for ind in range(m):
  s, c = map(int, input().split())
  if digit[s-1] == None:
    digit[s-1] = c
  elif digit[s-1] != c:
    print(-1)
    exit()

nums = [0] * n
for ind, num in enumerate(digit):
  if num != None:
    nums[ind] = num

if n > 0 and nums[0] == 0:
  print(-1)
result = 0
for ind, num in enumerate(nums):
  result += 10**(n-ind-1) * num
print(result)

Failing test case input:
3 0
1 0

Expected output:
100


Actual output:
-1


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

if n > 1 and digit[0] == 0:
  print("-1")
  exit()
nums = [0] * n
for ind, num in enumerate(digit):
  if ind == 0 and num == None:
    nums[ind] = 1
  if num != None:
    nums[ind] = num
result = 0
for ind, num in enumerate(nums):
  result += 10**(n-ind-1) * num
print(result)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int,input().split())
z = []
for i in range(n):
  z.append(-1)
for i in range(m):
  x1,y1=[int(i) for i in input().split()]
  if z[x1-1] != -1:
    if z[x1-1] != y1:
      print(-1)
      exit(0)
  z[x1-1] = y1
if z[0] == -1:
  z[0] = 1
for i in range(1,n):
  if z[i] == -1:
    z[i] = 0
for s in z:
  print(s, end ="")

Failing test case input:
3 2
1 0
0 0

Expected output:
-1


Actual output:
000

Fixed submission (verdict: Accepted):
n, m = map(int,input().split())
z = []
for i in range(n):
  z.append(-1)
for i in range(m):
  x1,y1=[int(i) for i in input().split()]
  if z[x1-1] != -1:
    if z[x1-1] != y1:
      print(-1)
      exit(0)
  if x1 == 1:
    if y1 == 0:
      if n != 1:
        print(-1)
        exit(0)
  z[x1-1] = y1
if n != 1:
  if z[0] == -1:
    z[0] = 1
else:
  if z[0] == -1:
    z[0] = 0
for i in range(1,n):
  if z[i] == -1:
    z[i] = 0
for s in z:
  print(s, end ="")
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
    n, m = map(int, input().split())
    joken_list = [tuple(map(int, input().split())) for i in range(m)]

    init_num = 0
    limit_num = 10 ** n

    result = "-1"
    for i in range(init_num, limit_num):
        i_s = str(i)
        match = True
        for keta, value in joken_list:
            if i_s[keta - 1 : keta] != str(value):
                match = False
                break

        if match:
            result = i_s
            break

    print(result)

if __name__ == '__main__':
    main()


Failing test case input:
3 1
1 1
1 3

Expected output:
100


Actual output:
1


Fixed submission (verdict: Accepted):



def main():
    n, m = map(int, input().split())
    joken_list = [tuple(map(int, input().split())) for i in range(m)]

    init_num = 0
    if n > 1:
        init_num = 10 ** (n - 1)
    limit_num = 10 ** n

    result = -1
    for i in range(init_num, limit_num):
        match = True
        for keta, value in joken_list:
            if str(i)[keta - 1] != str(value):
                match = False
                break

        if match:
            result = i
            break

    print(result)


if __name__ == '__main__':
    main()

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
ms = [[j for j in str(i)] for i in range(100000)]
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = []

for item in ms:
    if len(item) == n:
        for num, res in enumerate(s):
            if item[res[0] - 1] != str(res[-1]):
                break
            if num == len(s) - 1:
                lis.append(int("".join(item)))
if lis:
    print(min(lis))
else:
    print(-1)

Failing test case input:
3 0
1 1
0 0

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = []
for i in range(10**n):
    num = list(str(i))
    if len(num) == n:
        flag = True
        for j in s:
            if num[j[0] - 1] != str(j[-1]):
                flag = False
        if flag:
            lis.append(i)
            break
if lis:
    print(lis[0])
else:
    print(-1)

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

import math
n,m=map(int,input().split())
ans=[0]*n
flag=False
for i in range(m):
    s,c=map(int,input().split())
    ans[s-1]=c
    if s-1==0:
        flag=True

if not flag:
    ans[0]=1
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()


Failing test case input:
3 3
1 14
3 2
1 7

Expected output:
-1


Actual output:
702


Fixed submission (verdict: Accepted):

import math
n,m=map(int,input().split())
ans=['l']*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='l':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
if ans[0]=='l' and n>1:
    ans[0]=1
for i in range(n):
    if ans[i]=='l':
        ans[i]=0
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
ms = [[j for j in str(i)] for i in range(10**n)]
s = [list(map(int, input().split())) for _ in range(m)]
lis = []

for item in ms:
    if len(item) == n:
        for num, res in enumerate(s):
            if item[res[0] - 1] != str(res[-1]):
                break
            elif num == len(s) - 1:
                lis.append(int("".join(item)))
                break
if lis:
    print(min(lis))
else:
    print(-1)

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())
s = [list(map(int, input().split())) for _ in range(m)]
lis = []
for i in range(10**n):
    num = list(str(i))
    if len(num) == n:
        flag = True
        for j in s:
            if num[j[0] - 1] != str(j[-1]):
                flag = False
        if flag:
            lis.append(i)
            break
if lis:
    print(lis[0])
else:
    print(-1)

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if flg[s[j]-1] != 1 or ans[s[j]-1] == c[j]:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    else:
        print(-1)
        exit()
if n > 1 and ans[0] == 0 :
    print(-1)
else:
    print(''.join(map(str,ans)))

Failing test case input:
2 1
0 1
1 0

Expected output:
11


Actual output:
-1


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and flg[0] == 1 and ans[0] == 0 :
    print(-1)
elif n > 1 and flg[0] == 0:
    ans[0] = 1
    print(''.join(map(str,ans)))
    exit()
else:
    print(''.join(map(str,ans)))

Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M = map(int,input().split())
ret = ['a','a','a']
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
ans = ''
for i in range(3):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0:
      ans += '1'
    else:
      ans += '0'
print(int(ans))

Failing test case input:
1 1
0 1
1 0

Expected output:
1


Actual output:
101


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
ret = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
if ret[0] == 0:
  if N != 1:
    print(-1)
    exit()
ans = ''
for i in range(N):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0 and N > 1:
      ans += '1'
    else:
      ans += '0'
print(int(ans))
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    ans = [-1]* n
    for s, c in sc:
        s -= 1 
        if ans[s] == -1or ans[s] == c:
            ans[s] = c
        else:
            print(-1)
            return
        
    if ans[0] == -1:
        ans[0] = 1
    elif ans[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return
    
    print(''.join(list(map(str, ans))).replace('-1', '0'))
    
if __name__ == '__main__':
    main()

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    ans = [-1]* n
    for s, c in sc:
        s -= 1 
        if ans[s] == -1or ans[s] == c:
            ans[s] = c
        else:
            print(-1)
            return
        
    if ans[0] == -1 and n >1:
        ans[0] = 1
    elif ans[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return
    
    print(''.join(list(map(str, ans))).replace('-1', '0'))
    
if __name__ == '__main__':
    main()

Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
ans = [10]*(N)
for i in range(M):
    si,ci = map(int,input().split())
    if ans[si-1] == 10:
        ans[si-1] = ci
    elif ans[si-1] != ci:
        ans[0] = -1

for i in range(1,N):
    if ans[i] == 10:
        ans[i] = 0
if ans[0] == 10: ans[0] = 1

if ans[0] > 0:
    res = 0
    for i in range(N):
        res += ans[i]*10**(N-i-1)
elif ans[0] == -1:
    res = -1
else:
    if N == 0:
        res = 0
    else:
        res = -1

print(res)


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 = [10]*N
for i in range(M):
    si,ci = map(int,input().split())
    if ans[si-1] == 10:
        ans[si-1] = ci
    elif ans[si-1] != ci:
        ans[0] = -1

for i in range(1,N):
    if ans[i] == 10:
        ans[i] = 0
if ans[0] == 10:
    if N != 1:
        ans[0] = 1
    else:
        ans[0] = 0

if ans[0] > 0:
    res = 0
    for i in range(N):
        res += ans[i]*10**(N-i-1)
elif ans[0] == -1:
    res = -1
else:
    if N == 1:
        res = 0
    else:
        res = -1

print(res)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N,M = map(int,input().split())
res = ['a' for _ in range(N)]
for i in range(M):
  s,c = map(int,input().split())
  if res[s-1] != 'a' and res[s-1] != str(c):
    print('-1')
    sys.exit(0)
  else:
    res[s-1] = str(c)
for i in range(N):
    if res[i] == 'a':
        if i == 0:
            res[i] = '1'
        else:
            res[i] = '0'
st = ''
for i in range(N):
  st += res[i]
if st[0] == '0' and len(st) > 1:
  print('-1')
  sys.exit(0)
print(st)

Failing test case input:
1 0
0 0
2 3

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
N,M = map(int,input().split())
if (N,M) == (1,0):
    print('0')
    sys.exit(0)
res = ['a' for _ in range(N)]
for i in range(M):
  s,c = map(int,input().split())
  if res[s-1] != 'a' and res[s-1] != str(c):
    print('-1')
    sys.exit(0)
  else:
    res[s-1] = str(c)
for i in range(N):
    if res[i] == 'a':
        if i == 0:
            res[i] = '1'
        else:
            res[i] = '0'
st = ''
for i in range(N):
  st += res[i]
if st[0] == '0' and len(st) > 1:
  print('-1')
  sys.exit(0)
print(st)

Problem: p02761
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
n, m = map(int, input().split())
ans = ['*'] * n

for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    c = str(c)
    if ans[s] == '*':
        ans[s] = c
    elif ans[s] != c:
        print('-1')
        sys.exit()

ans = ''.join(ans).replace('*', '0')

if ans[0] == '0' and len(ans) > 1:
    print(-1)
    sys.exit()

print(ans)


Failing test case input:
3 0
1 0

Expected output:
100


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
n, m = map(int, input().split())
ans = ['*'] * n

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

ans = ''.join(ans).replace('*', '0')

if ans[0] == '0' and len(ans) > 1:
    ans = '1' + ans[1:]

print(ans)
Problem: p02761
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
a = [[] for _ in range(N)]
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
ans = [0]*N
 
for i in range(len(a)):
  if i == 0 and a[i]:
    if len(set(a[i]))> 1 or 0 in a[i]:
      flag = 1
      break
    else:
      ans[i] = a[i][0] 
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if flag == 0:
  if ans[0] == 0:
    ans[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  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 _ in range(N)]
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
ans = [0]*N
 
for i in range(len(a)): 
  if i == 0 and a[i]:
    if len(a) == 1:
      pass
    elif len(set(a[i]))> 1 or 0 in a[i]:
      flag = 1
      break
    else:
      ans[i] = a[i][0] 
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if flag == 0:
  if ans[0] == 0:
    if len(a) == 1:
      ans[0] = 0
    else:
      ans[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  print(-1)

Problem: p02761
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]
def exit():
    import sys
    print(-1)
    sys.exit()
num=['']*n
for i in range(m):
    if s[i]==[1,0]:
        exit()
    if num[s[i][0]-1]!='':
        if num[s[i][0]-1]==s[i][1]:
            continue
        else:
            exit()
    else:
        num[s[i][0]-1]=s[i][1]
else:
    print(num[0] if num[0]!='' else 1, end='')
    for i in range(1,n):
        print(num[i] if num[i]!='' else 0, end='')

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())
def exit():
    import sys
    print(-1)
    sys.exit()
num=['']*n
for s,c in (map(int,input().split()) for i in range(m)):
    if n>1 and [s,c]==[1,0]:
        exit()
    if num[s-1]!='':
        if num[s-1]==c:
            continue
        else:
            exit()
    else:
        num[s-1]=c
else:
    if n==1:
        print(num[0] if num[0]!='' else 0, end='')
    else:
        print(num[0] if num[0]!='' else 1, end='')
    for i in range(1,n):
        print(num[i] if num[i]!='' else 0, end='')