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
    else:
        flg |= 1<<(s-1)
        ans[s-1] = c


ans = ''.join(map(str, ans))

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