import numpy as np


n,m= map(int, input().split())
#print(n,m)

A=[]
for i in range(0,m):
    input_1= list(map(int, input().split()))
    A.append(input_1)
#print(A)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

#print(get_unique_list(A))

B=get_unique_list(A)

'''
for i in range(0,len(B)):
    if B[i][0]
    Answer+=pow(10,n-B[i][0])*B[i][1]
'''
Answer=0
count=0
for i in range(0,len(B)):
    Answer+=pow(10,n-B[i][0])*B[i][1]
    count+=pow(10,n-B[i][0])
    
print(count)
count1=[]    
for i in range(1,len(str(count))):
    count1.append(count//(pow(10,i-1)))
print(count1)

count2=list(set(count1))

for i in range(0,len(count2)):
    if count2[i]==0 :#or count1!=1:
        del(count2[i])
        count2.append('')
    if count2[i]==1:
        del(count2[i])
        count2.append('')

count3=list(set(count2))
print(count3)

if count3==['']:
    print(Answer)
else:
    print(-1)