n,m = map(int, input().split())

nums = [-1]*n
for i in range(m):
  s,c = map(int, input().split())
  s -= 1
  if nums[s] == -1: nums[s] = c
  elif nums[s] != -1 and nums[s] != c:
    print(-1)
    exit()

for i in range(n):
  if i == 0:
    if n == 1 and nums[0] == -1: 0
    elif nums[0] == -1: nums[0] = 1
  else:
    if nums[i] == -1: nums[i] = 0

ans = ""
for i in nums:
  ans += str(i)
  
if len(str(int(ans))) == n:
  print(ans)
else:
  print(-1)