N, M = map(int, input().split())
SC = [[int(x) for x in input().split()] for _ in range(M)]

ans = [0] * N
flg = 0
flg2 = True

for s, c in SC:
    if (flg>>(s-1))&1:
        if ans[s-1] != c:
            flg2 = False
            break
    if N>2 and s==1 and c==0:
        flg2=False
        break
    else:
        flg |= 1<<(s-1)
        ans[s-1] = c

if not any(ans):
    flg2=False

if N>2 and ans[0]==0:
    ans[0]=1
ans = ''.join(map(str, ans))
if len(str(int(ans)))!=N:
    flg2=False  
if flg2:
    print(int(ans))
else:
    print(-1)