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 M==0:
  if N==1:
    print("0")
    exit()
  print(str(10**N-1))
  exit()
      
if ((N == 1) and (digit[0] == 0)):
  print("0")
  exit()
    
if digit[0] == 0:
  print("-1")
  exit()

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