N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
f = True
r = [0]*N

for i in range(M):
  a = sc[i][0]-1
  b = sc[i][1]
  if r[a] == 0 or r[a] == b:
    r[a] = b
  else:
    f=False
  
if r[0] == 0:
  f=False
  
ans = ""
for i in range(N):
  ans += str(r[i])
  
if f:
  print(ans)
else:
  print(-1)