nm = list(map(int,input().split()))
n = nm[0]
m = nm[1]
sc = [map(int,input().split()) for _ in range(m)]
s,c = [list(i) for i in zip(*sc)]
l = [10] * n
for i in range(m):
    if l[s[i]-1] == 10:
        l[s[i]-1] = c[i]
    else:
        if l[s[i]-1] == c[i]: pass
        else: l[s[i]-1] = -1
if -1 in l:
    print(-1)
else:
    if l[0] == 0:
        print(-1)
    else:
        if l[0] == 10:
            l[0] = 1
            for i in range(len(l)):
                if l[i] == 10:
                    l[i] = 0
            for i in range(len(l)):
                print(l[i],end="")
        else:
            for i in range(len(l)):
                if l[i] == 10:
                    l[i] = 0
            for i in range(len(l)):
                print(l[i],end="")