N, M = map(int,input().split())
num = ["9"]*N
l = [list(map(int,input().split())) for i in range(M)]
l = sorted(l)
for i in range(M):
  if l[i][0] == 1 and l[i][1] == 0:
    print(-1)
    exit()
  if i < M-1 and l[i][0] == l[i+1][0] and l[i][1] != l[i+1][1]:
    print(-1)
    exit()
  num[l[i][0]-1] = l[i][1]
for i in range(N):
  if num[i] == "9":
    num[i] = 0
print("".join(map(str,num)))