n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]   
ans = [0 for _ in range(n)]

flg = True
for x,y in l:
    if ans[x-1] == 0 or ans[x-1] == y:
        ans[x-1] = y
    else:
        flg = False
        break


ans = [str(i) for i in ans]

if ans[0] == '0':flg = False

print(''.join(ans) if flg else -1)    




