N, M = map(int, input().split())
s_c = [list(map(int, input().split())) for _ in range(M)]

s_c = sorted(s_c, key=lambda x: x[0])
ans= ""
#print(s_c)
f = True
for i in range(N):
  tmp = []
  for j in range(M):
    if s_c[j][0] == 1 and s_c[j][1] == 0:
      f = False
      break
    if s_c[j][0] == i + 1:
      tmp.append(s_c[j][1])
  if len(set(tmp)) == 1:
    ans += str(tmp[0])
  elif len(set(tmp)) >= 2:
    f = False
    break
  else:
    if i == 0:
      ans += "1"
    else:
      ans += "0"
if f:
  print(ans)
else:
  print("-1")