n, m = map(int, input().split())
sc_list = [[int(i) for i in input().split()] for _ in range(m)]

number_list = [-1 for _ in range(n)]
flag = True

for sc in sc_list:
    s = sc[0]
    c = sc[1]
    if number_list[s-1] != -1 and number_list[s-1]!=c:
        print(-1)
        flag = False
        break
    else:
        number_list[s-1] = c
        
if number_list[0] == 0:
    print(-1)
    flag = False
else:
    while -1 in number_list:
        i = number_list.index(-1)
        number_list[i] = 0
        
if number_list[0] == 0:
    number_list[0] = 1
    
if flag:
    print(''.join([str(i) for i in number_list]))