n,m = map(int, input().split())

num = [-1]*n
for i in range(m):
  s,c = map(int, input().split())
  if num[s-1] != -1 and num[s-1] != c:
    print(-1)
    exit()
  num[s-1] = c
  
for i in range(n):
  if num[i] == -1:
    num[i] = 0
    
ans = ""
for i in num:
  ans += str(i)
if len(str(int(ans))) != n:
  print(-1)
else:
  print(ans)