N, M = map(int, input().split())
#SC = [list(map(int, input().split())) for i in range(M)]
define = [0] * N
ans = [0] * N

for i in range(M):
  s, c = map(int, input().split())
  if define[s - 1] == 1:
    #print("y")
    if c != ans[s-1]:
      print("-1")
      quit()
  else:
    define[s - 1] = 1
    ans[s-1] = c

if ans[0] == 0:
  print("-1")
  quit()
  
for i in range(N):
  print(ans[i], end = "")