Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)

flag = True
for i in range(n):
  if len(digit[i]) > 1:
    digit[i] = list(set(digit[i]))
  if len(digit[i]) > 1:
    flag = False

if n == 3:
  if len(digit[0]) > 0:
    if digit[0][0] == "0":
      flag= False
if n == 2:
  if len(digit[0]) > 0:
    if digit[0][0] == "0":
      flag = False

      
if flag:
  ans = []
  for i in range(10**(n-1),10**n):
    tmp = 0
    count =10**(n-1)
    for j in range(len(digit)):
      if len(digit[j]) > 0:
        tmp+=count*int(digit[j][0])
      count/=10
    if i == tmp:
      ans.append(i)
  print(min(ans))
else:
  print(-1)


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

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

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)

flag = True
for i in range(n):
  if len(digit[i]) > 1:
    digit[i] = list(set(digit[i]))
  if len(digit[i]) > 1:
    flag = False

if flag:
  ans = []
  for i in range(10**(n-1),10**n):
    tmp = 0
    count =10**(n-1)
    for j in range(len(digit)):
      if len(digit[j]) > 0:
        tmp+=count*int(digit[j][0])
      count/=10
    if i == tmp:
      ans.append(i)
  print(min(ans))  
else:
  print(-1)


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

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

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

tmp = ["0" for i in range(n)]
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)
for i in range(n):
  if len(digit[i]) == 0:
    digit[i].append("0")
  

ans = []
if n == 3:
  for i in range(len(digit[0])):
    for j in range(len(digit[1])):
      for k in range(len(digit[2])):
        t = int(digit[0][i] + digit[1][j]+digit[2][k])
        if len(str(t)) == n:
          ans.append(t)  
if n ==2:
  for i in range(len(digit[0])):
    for j in range(len(digit[1])):
      t = int(digit[0][i] + digit[1][j]+digit[2][k])
      if len(str(t)) == n:
        ans.append(t)
if n == 1:
  for i in range(len(digit[0])):
    t = int(digit[0][i])
    ans.append(t)
    
if len(ans) == 0:
  print(-1)
else:
  print(min(ans))
  


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

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