Buggy python submission (verdict: Runtime Error):
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return -1
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return -1
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))


Fixed submission:
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return [str(-1)]
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return [str(-1)]
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))

Buggy python submission (verdict: Runtime Error):
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return -1
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return -1
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int(assign_digits(ans)))


Fixed submission:
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return [str(-1)]
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return [str(-1)]
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))