N, M = (int(x) for x in input().split())
s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = [int(p) for p in input().split()]

n = [0]*N

for j in range(len(s)):
  if N > 1 and s[j] == 1 and c[j] == 0:
    print(-1)
    exit()
for p in range(len(s)):
  for q in range(len(s)):
    if p == q:
      pass
    else:
      if s[p] == s[q] and c[p] != c[q]:
        print(-1)
        exit()		
for k in range(M):
  l = s[k]
  n[l-1] = c[k]
if n[0] == 0:
  n[0] = 1
print(n)
resstr = [str(x) for x in n]
res = "".join(resstr)
result = int(res)   
print(result)