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