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

ans = [None] * N
for s,c in SC:
    s -= 1
    if ans[s] is None or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()
if N > 1 and ans[0] == 0:
    print(-1)
    exit()

a = ''.join(map(lambda x:str(x) if x else '0', ans))
print('1' + a[1:] if a[0]=='0' else a)