n , m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

#n,m = 2,2
#sc = [[1, 0],[1, 0]]

ans = 0
x = [99] * (n+1)
for s,c in sc:
  if x[s] == 99:
    x[s] = c
  else:
    if x[s] != c:
      ans = -1
      break

x = [99] * (n+1)
for s,c in sc:
  x[s] = c

if ans != -1:
  ans = ''
  for i in range(1,n+1):
    if x[i] == 99:
      x[i] = 0
    ans = ans + str(x[i])

print(ans)