Buggy python submission (verdict: Runtime Error):
N, M = input().split()
N = int(N)
M = int(M)
S = []
C = []
A = []
zero_flag = False
for m in range(M):
  s, c = input().split()
  s = int(s)
  c = int(c)
  S.append(s)
  C.append(c)
  if s == 2 and c == 0 and N == 2:
    A.append('0')
  elif s == 2 and c == 0 and N == 3:
    A.append('00')
  elif s == 3 and c == 0 and N == 3:
    A.append('0') 
  else:
  	A.append(str((10**(N-(s-1)-1)) * c))
  if s == 1 and c == 0 and N != 2:
    zero_flag = True
    
flag = False
for a1 in A:
  for a2 in A:
    if a1 != a2 and len(a1) == len(a2):
      if a1 != a2:
        flag = True

if zero_flag:
  print('-1')
elif flag:
  print('-1')
else:
  ans = list(set(A))
  sum_ans = 0
  for a in ans:
    sum_ans += int(a)
  if sum_ans < (10**(N-(s-1)-1)):
  	sum_ans = sum_ans + (10**(N-1)) 
  print(sum_ans)


Fixed submission:
N, M = input().split()
N = int(N)
M = int(M)
S = []
C = []
A = []
zero_flag = False
for m in range(M):
  s, c = input().split()
  s = int(s)
  c = int(c)
  S.append(s)
  C.append(c)
  if s == 2 and c == 0 and N == 2:
    A.append('0')
  elif s == 2 and c == 0 and N == 3:
    A.append('00')
  elif s == 3 and c == 0 and N == 3:
    A.append('0') 
  else:
  	A.append(str((10**(N-(s-1)-1)) * c))
  if s == 1 and c == 0 and N != 1:
    zero_flag = True

flag = False
for a1 in A:
  for a2 in A:
    if a1 != a2 and len(a1) == len(a2):
      if a1 != a2:
        flag = True

if zero_flag:
  print(-1)
elif flag:
  print(-1)
else:
  ans = list(set(A))
  sum_ans = 0
  for a in ans:
    sum_ans += int(a)
  if sum_ans < (10**(N-1)) and N != 1:
  	sum_ans = sum_ans + (10**(N-1)) 
  print(sum_ans)

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
N = int(N)
M = int(M)
S = []
C = []
A = []
zero_flag = False
for m in range(M):
  s, c = input().split()
  s = int(s)
  c = int(c)
  S.append(s)
  C.append(c)
  if s == 2 and c == 0 and N == 2:
    A.append('0')
  elif s == 2 and c == 0 and N == 3:
    A.append('00')
  elif s == 3 and c == 0 and N == 3:
    A.append('0') 
  else:
  	A.append(str((10**(N-(s-1)-1)) * c))
  if s == 1 and c == 0 and N != 2:
    zero_flag = True
    
flag = False
for a1 in A:
  for a2 in A:
    if a1 != a2 and len(a1) == len(a2):
      if a1 != a2:
        flag = True

if zero_flag:
  print('-1')
elif flag:
  print('-1')
else:
  ans = list(set(A))
  sum_ans = 0
  for a in ans:
    sum_ans += int(a)
  if sum_ans < (10**(N-(s-1)-1)):
  	sum_ans = sum_ans + (10**(N-1)) 
  print(sum_ans)


Fixed submission:
N, M = input().split()
N = int(N)
M = int(M)
S = []
C = []
A = []
zero_flag = False
for m in range(M):
  s, c = input().split()
  s = int(s)
  c = int(c)
  S.append(s)
  C.append(c)
  if s == 2 and c == 0 and N == 2:
    A.append('0')
  elif s == 2 and c == 0 and N == 3:
    A.append('00')
  elif s == 3 and c == 0 and N == 3:
    A.append('0') 
  else:
  	A.append(str((10**(N-(s-1)-1)) * c))
  if s == 1 and c == 0 and N != 1:
    zero_flag = True

flag = False
for a1 in A:
  for a2 in A:
    if a1 != a2 and len(a1) == len(a2):
      if a1 != a2:
        flag = True

if zero_flag:
  print(-1)
elif flag:
  print(-1)
else:
  ans = list(set(A))
  sum_ans = 0
  for a in ans:
    sum_ans += int(a)
  if sum_ans < (10**(N-1)) and N != 1:
  	sum_ans = sum_ans + (10**(N-1)) 
  print(sum_ans)