X = list(map(int,input().rstrip().split()))
N = X[0]
M = X[1]

tmp = [-1] * N
b = []
res = 0
for i in range(M):
  b.append(list(map(int,input().rstrip().split())))

  
for j in range(M):
  k = b[j][0] -1
  l = b[j][1]	
  if tmp[k] == -1:
    tmp[k] = l
  elif tmp[k] != l:
    res = -1

#if res != -1 :
#  if N != 1 and tmp[0] == 0:
#    res = -1
  
if res != -1 :
  res = ''
  for f in range(N):
    if tmp[f] == -1:
      tmp[f] = 0
    res = res + str(tmp[f])
  res = int(res)

  if len(str(res)) != N :
    res = -1
  
print(res) 
    
