N,M = map(int,input().split())
order = {}
if N==1 and M==0:
  print(0)
else:
  for i in range(M):
    s,c = map(int,input().split())
    if order.get(s,x)==x:
        order[s]=c
    elif order.get(s,x)!=x and order[s]!=c:
        print(-1)
        break
  else:
    moji = [1]+[0]*(N-1)
    for k in order.keys():
        moji[k-1]=order[k]
    if N!=1 and moji[0]==0:
      print(-1)
    else:
      print(''.join([str(a) for a in moji]))
