n,m = map(int,input().split())
list_all = list(list(input().split())for i in range(m))
list_a = list(int(i[0])for i in list_all) 
list = list(int(i[1]) for i in list_all)

range = [0]*n 
bool = [False]*n 


for k in list_a:
    if bool[k-1] == True:
        if range[k-1]==list[list_a.index(k)]:
            continue
        else:
            print('-1')
            exit()
        
        
    else:
        bool[k-1] = True
        range[k-1] = list[list_a.index(k)]

if range[0]==0:
    print('-1')
else:
    print(''.join(map(str,range)))    