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

lst = [-1]*N
flag = False
zero = False
for _ in range(M):
  s,c = map(int,input().split())
  if lst[s-1] > -1 and lst[s-1] != c:
    flag = True
  elif s == 1 and c == 0:
    flag = True
  else:
    lst[s-1] = c

if lst.count(0) == len(lst):
  zero = True
    
if flag and not zero:
  print("-1")
elif zero:
  print("0")
else:
  for i in range(N):
    if i == 0 and lst[i] == -1:
      lst[i] = 1
    elif lst[i] == -1:
      lst[i] = 0
  print("".join(map(str,lst)))