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