cnt = 0
po = 1
n,m = map(int,input().split())
ans = [0 for i in range(n)]
if(m == 0):
  print(0)
  exit()
sc = [list(map(int,input().split())) for i in range(m)]
for i in sc:
  if(ans[i[0]-1] != 0 and ans[i[0]-1] != i[1]):
    print(-1)
    exit()
  else:	
    ans[i[0]-1] = i[1]
if(ans[0] == 0 and n != 1):
  ans[0] = 1
for i in range(n-1,-1,-1):
  cnt += ans[i] * po
  po *= 10
print(cnt)