import sys
N,M = map(int,input().split())
if N > 1 and M == 0:
  print(-1)
  sys.exit()
  
num = [0]*N

for i in range(M):
  si,ci = map(int,input().split())
  if si == 1 and ci == 0:
    print(-1)
    sys.exit()
  if num[si-1] != 0 and ci != num[si-1]:
    print('-1')
    sys.exit()
  num[si-1] = ci
if num[0] == 0:  
  for i in range(1,N):
    if num[i] != 0:
      num[0] = 1
      break
    if i ==N-1:
      print(-1)
      sys.exit()
n = int(''.join(map(str,num)))
print(n)
          