N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

okflag = True

for i in range(M):

    if not okflag:
         break
    for j in range(M):
     if not okflag:
         break
     if not (i==j):
        if s[i]==s[j] and c[i]!=c[j]:

            okflag = False
            print("No")

if okflag:
    answer = ["x"] * N

    for i in range(M):
        answer[s[i]-1] = str(c[i])
    
    if N == 1 and answer[0] == "x":
        print("0")

    elif N == 1 and not answer[0] == "x":
        print(answer[0])

    elif not N == 1 and answer[0] == "0":
        print("-1")
    
    elif not N == 1 and not answer[0] == "0":
        for i in range(N):
            if answer[i] == "x":
                if i == 0:
                    answer[i] = "1"
                else:
                    answer[i] = "0"
        result = ''.join(answer)
        print(result)
    
