Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = []
for i in range(m):
  sc.append(list(map(int,input().split())))

sc1 = []
sc2 = []
sc3 = []
for i in sc:
  if i[0]==1:
    sc1.append(i[1])
  elif i[0]==2:
    sc2.append(i[1])
  else:
    sc3.append(i[1])

if len(set(sc1)) > 1 or len(set(sc2)) > 1 or len(set(sc3)) > 1:
  print('-1')
  exit()
elif len(set(sc1)) <= 1 and list(set(sc1))[0] == 0:
  print('-1')
  exit()


c1 = list(set(sc1))
c2 = list(set(sc2))
c3 = list(set(sc3))

if c1:
  c1_ans = c1[0]
else:
  c1_ans = 1
if c2:
  c2_ans = c2[0]
else:
  c2_ans = 0
if c3:
  c3_ans = c3[0]
else:
  c3_ans = 0

print(100*c1_ans + 100*c2_ans + c3_ans)

Fixed submission:
n,m = map(int,input().split())
c1 = []
c2 = []
c3 = []
for i in range(m):
  sc = list(map(int,input().split()))
  if sc[0] == 1:
    c1.append(sc[1])
  elif sc[0] == 2:
    c2.append(sc[1])
  else:
    c3.append(sc[1])

if len(set(c1)) <= 1 and len(set(c2)) <= 1 and len(set(c3)) <= 1:
  if 0 in list(set(c1)):
    if n == 1 and len(set(c1)) == 1 and len(set(c2)) == 0 and len(set(c3)) == 0:
      print('0')
      exit()
    else:
      print('-1')
      exit()
  elif not c1 and not c2 and not c3:
    if n == 1:
      print('0')
      exit()
    elif n == 2:
      print('10')
      exit()
    else:
      print('100')
      exit()
  else:
    if list(set(c1)):
      ans_c1 = list(set(c1))[0]
    else:
      ans_c1 = 1
    if list(set(c2)):
      ans_c2 = list(set(c2))[0]
    else:
      ans_c2 = 0
    if list(set(c3)):
      ans_c3 = list(set(c3))[0]
    else:
      ans_c3 = 0
else:
  print('-1')
  exit()

if n == 1:
  print(ans_c1)
elif n == 2:
  print(ans_c1*10 + ans_c2)
else:
  print(ans_c1*100 + ans_c2*10 + ans_c3)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())

if m==0:
  print(0)
  exit()

s = []
c = []
for i in range(m):
  sc = input().replace(' ','')
  s.append(int(sc[-2]))
  c.append(int(sc[-1]))

s1 = []
s2 = []
s3 = []
c1 = []
c2 = []
c3 = []
for i in range(m):
  if s[i] == 1 and not s1:
    s1.append(s[i])
    c1.append(c[i])
  elif s[i] == 1 and s1 and c[i] == c1[0]:
    next
  elif s[i] == 1 and s1 and c[i] != c1[0]:
    print(-1)
    exit()
  elif s[i] == 2 and not s2:
    s2.append(s[i])
    c2.append(c[i])
  elif s[i] == 2 and s2 and c[i] == c2[0]:
    next
  elif s[i] == 2 and s2 and c[i] != c2[0]:
    print(-1)
    exit()
  elif s[i] == 3 and not s3:
    s3.append(s[i])
    c3.append(c[i])
  elif s[i] == 3 and s3 and c[i] == c3[0]:
    next
  elif s[i] == 3 and s3 and c[i] != c3[0]:
    print(-1)
    exit()
ans = 0
if c1[0]==0:
  print(-1)
  exit()
elif not c1:
  next
else:
  ans+=c1[0]*100

if not c2:
  next
else:
  ans+=c2[0]*10

if not c3:
  next
else:
  ans+=c3[0]

print(ans)

Fixed submission:
n,m = map(int,input().split())
c1 = []
c2 = []
c3 = []
for i in range(m):
  sc = list(map(int,input().split()))
  if sc[0] == 1:
    c1.append(sc[1])
  elif sc[0] == 2:
    c2.append(sc[1])
  else:
    c3.append(sc[1])

if len(set(c1)) <= 1 and len(set(c2)) <= 1 and len(set(c3)) <= 1:
  if 0 in list(set(c1)):
    if n == 1 and len(set(c1)) == 1 and len(set(c2)) == 0 and len(set(c3)) == 0:
      print('0')
      exit()
    else:
      print('-1')
      exit()
  elif not c1 and not c2 and not c3:
    if n == 1:
      print('0')
      exit()
    elif n == 2:
      print('10')
      exit()
    else:
      print('100')
      exit()
  else:
    if list(set(c1)):
      ans_c1 = list(set(c1))[0]
    else:
      ans_c1 = 1
    if list(set(c2)):
      ans_c2 = list(set(c2))[0]
    else:
      ans_c2 = 0
    if list(set(c3)):
      ans_c3 = list(set(c3))[0]
    else:
      ans_c3 = 0
else:
  print('-1')
  exit()

if n == 1:
  print(ans_c1)
elif n == 2:
  print(ans_c1*10 + ans_c2)
else:
  print(ans_c1*100 + ans_c2*10 + ans_c3)