n,m = map(int, input().split())
l = [0]*n

for i in range(m):
    s,c = map(int, input().split())
    if l[s-1] == 0 or l[s-1] == str(c):
        l[s-1] = str(c)
    else:
        print(-1)
        exit()

if l[0] != 0 and l[0] != "0":
    l=[str(a) for a in l]
    print(''.join(l))
else:
    print(-1)