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

ans = [0] * n
exist = []
flag = 0
for _ in range(m):
  s, c = map(int, input().split())
  if (s == 1) and (c == 0):
    flag += 1
  if (s in exist) and (ans[s-1] != c):
    flag += 1
  else:
    ans[s-1] = c
    exist.append(s)
stop = 0
while ans[stop] == 0:
  if stop+1 not in exist:
    ans[stop] = 1
  stop += 1
  if stop == n:
    break
  
if flag >= 1:
  print(-1)
else:
  print(int("".join([str(i) for i in ans])))