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

ans = ['*'] * N

if N == 1 and sc_list[0][1] == 0:
    print(0)
    exit()

for sc in sc_list:
    s, c = sc
    if s == 1 and c == 0:
        print('-1')
        exit()
    if ans[s - 1] != '*' and int(ans[s - 1]) != c:
        print('-1')
        exit()
    ans[s - 1] = str(c)


ans = ''.join(ans)
print(ans.replace('*', '0'))
