N,M = list(map(int,input().split()))
s = []
for i in range(M):
    array = list(map(int,input().split()))
    s.append(array)
 
t = ["q" for i in range(N)]
a = 0
for i in range(M):
    if t[s[i][0]-1] == "q" or t[s[i][0]-1] ==s[i][1]:
        t[s[i][0]-1] = s[i][1]
    else:
        a += 1
 
if a >= 1 or t[0] == 0:
    print(-1)
else:
    if t[0] == "q":
        if N == 1 or M == 0:
            t[0] = 0
        else:
            t[0] = 1
            for i in range(1,N):
                if t[i] == "q":
                    t[i] = 0
    else:
        for i in range(N):
            if t[i] == "q":
                t[i] = 0
    print("".join(map(str,t)))