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

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