from collections import Counter
N,M = map(int,input().split())
s = [0 for x in range(M)]
c = [0 for x in range(M)]
for i in range(M) :
    s[i],c[i] = map(int,input().split())

Matrix = [[0,0] for x in range(M)]
for i in range(M) : # Matrixは[s,c]
    Matrix[i][0] = s[i]
    Matrix[i][1] = c[i]

te = Counter(s)
chofuku = [i[0] for i in te.items() if i[1] >= 2]
flag = True

for i in range(len(chofuku)) :
    list_buf = []
    for j in range(M) :
        if Matrix[j][0] == chofuku[i] :
            list_buf.append(Matrix[j][1])
    #print(list_buf)

    if len(set(list_buf)) >= 2 :
        flag = False 
        print(-1)
        break

buf_list = ['' for x in range(N)]
buf = 0
if flag == True :
    list = [0 for x in range(N)]
    for i in range(M) :
        list[s[i]-1] = c[i]
    #print(list)
    if list[0] == 0 :
        print(-1)
    else :
        print(list)
        for i in range(len(list)) :
            buf += list[i] * (10**(len(list)-(i+1)))
        print(buf)