n,m = [int(x) for x in input().split()]
l = []
for i in range(m):
  a = [int(x) for x in input().split()]
  l.append(a)
ans = [0]*n
hantei = ""
for i in range(m):
  if ans[l[i][0]-1] == l[i][1] or ans[l[i][0]-1] == 0:
    ans[l[i][0]-1] = l[i][1]
  else:
    hantei = -1
    break
ans_str = [str(n) for n in ans]
if n != 0 and ans[0] == 0:
  hantei = -1
if hantei == "":
  hantei = "".join(ans_str)
print(hantei)