import sys

a = [int(i) for i in input().split()]
n = a[0]
m = a[1]

nums = [None for i in range(n)]
for i in range(m):
  a = [int(j) for j in input().split()]
  s = a[0]
  s_mod = s - 1
  c = a[1]
  if s_mod == 0 and c == 0:
    print(-1)
    sys.exit()
  
  if nums[s_mod] is not None and nums[s_mod] != c:
    print(-1)
    sys.exit()
    
  nums[s_mod] = c

print(''.join([str(0 if i is None else i) for i in nums]))