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

flag = True

if n == 1 and m == 0:
    print(0)
elif n == 1 and m != 0:
    if len(set(sc)) != 1:
        print(-1)
    else:
        print(sc[0][1])
        
        
elif n > 1 and m == 0:
    print(10*(n-1))
    
elif n > 1 and m != 0:
    for i in range(10**(n-1), 10**n):
        i_str = str(i)
        i_list = list(i_str)
        for item in set(sc):
            if i_list[item[0]-1] != str(item[1]):
                break
        else:
            print(i)
            flag = False
            break
    if flag:
        print(-1)