n, m = map(int, input().split())
s = [None] * m
c = [None] * m
for i in range(m):
  s[i], c[i] = map(int, input().split())
num = [0 for i in range(n)]
if n != 1:
  num[0] = 1
determined = [False for i in range(n)]
possible = True
for i in range(m):
  if s[i] == 1 and c[i] == 0:
    possible = False
    break
  if determined[s[i]-1] and num[s[i]-1] != c[i]:
    possible = False
    break
  num[s[i]-1] = c[i]
  determined[s[i]-1] = True

if not possible:
  print(-1)
else:
  for i in range(n):
    print(num[i], end="")
  print("")
