N, M = list(map(int, input().split()))
B = {}
for i in range(M):
  k, v = input().split()
  if (k in B) and (B.get(k)!=v):
    print(-1)
    exit()
  else:
    B[k] = v
if (N!=1) and (B.get("1", "0")=="0"):
  print(-1)
  exit()
ans = B.get("1", "1")
for i in range(2, N+1):
  ans = ans + str(B.get(i, 0))
print(ans)