N, M = map(int, input().split())
#SC = [list(map(int, input().split())) for i in range(M)]
define = [0] * N
ans = [0] * N
if M == 0:
  ans[0] = 1
  for i in range(N):
    print(ans[i], end = "")
  quit()
  
if N == 1:
  ans = 0
  define = 0
  for i in range(M):
    s, c = map(int, input().split())
    if s == 1:
      if define == 1:
        if c != ans:
          print("-1")
          quit()
      else:
        ans = c
        define = 1
  print(ans)      
  quit()  
  
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:
  if define[0] == 1:
    print("-1")
    quit()
  else:
    ans[0] = 1
  
for i in range(N):
  print(ans[i], end = "")