n, m = map(int, input().split())
if m == 0:
  print("-1")
  exit()
digit = [None] * n
for ind in range(m):
  s, c = map(int, input().split())
  if digit[s-1] == None:
    digit[s-1] = c
  elif digit[s-1] != c:
    print("-1")
    exit()
#print(digit)
if n > 0 and digit[0] == 0:
  print("-1")
  exit()
nums = [0] * n
for ind, num in enumerate(digit):
  if num != None:
    nums[ind] = num
#print(nums)
result = 0
for ind, num in enumerate(nums):
  result += 10**(n-ind-1) * num
print(result)