n,m=map(int, input().split())
import sys
listA = []
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
listB = []
for i in range(0,n):
  listB.append(-1)
for i in range(0,m):
  if listB[listA[i][0]-1] == -1 or listB[listA[i][0]-1] == listA[i][1]:
    listB[listA[i][0]-1] = listA[i][1]
  else:
    print(-1)
    sys.exit()
    
    
if listB[0] == 0 and n!=1:
  print(-1)
  sys.exit()
else:
  if listB[0]==-1:
    listB[0] = 1
  if listB[1]==-1:
    listB[1] = 0
  if listB[2]==-1:
    listB[2] = 0
  if n == 1:
    print(listB[0])
  elif n == 2:
    print(10*listB[0]+listB[1])
  else:
    print(100*listB[0]+10*listB[1]+listB[2])
    
    
    