#C
N, M = list(map(int, input().split()))
ins = False
ans = [0]*N
ok = True
for i in range(M):
    s, c = list(map(int, input().split()))
    if s==1 and c==0:
        ok = False
    if ans[s-1]==0 or ans[s-1]==c:
        ans[s-1] = c
    else:
        ok = False
    if s == 1:
        ins = True
    else:
        ins = False
answer = []
if ok == True:
    for i in range(len(ans)):
        answer.append(str(ans[i]))
    if ins==False:
        answer[0]='1'
    print(''.join(answer))
else:
    print('-1')