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

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

digit = [-1, -1, -1]

for i in range(M):
  if digit[s[i]] < 0:
    digit[s[i]] = c[i]
  else:
    if not(digit[s[i]] == c[i]):
      print("-1")
      exit()

if (N == 1) and (digit[0] == 0):
  print("0")
  exit()
    
if (digit[0] == 0) or (digit[0] == -1):
  print("-1")
  exit()

output = ""
  
for i in range(N):
  if digit[i] == -1:
    output += "0"
    continue
  output += str(digit[i])
  
print(output)
  