N, M = map(int,input().split())
check_lis = [-1 for _ in range(N)]
for _ in range(M):
    s,c = map(int,input().split())
    if check_lis[s-1] == -1:
        check_lis[s-1] = c
    else:
        if check_lis[s-1] != c:
            print('-1')
            break
    if check_lis[0] == 0:
        print('-1')
        break
else:
    min_range = 10 ** (N-1)
    if min_range == 1:
        min_range = 0
    for i in range(min_range, 10 * min_range):
        for idx, check in enumerate(check_lis):
            if check == -1:
                continue
            if (i // 10 ** (N - idx - 1)) % 10 != check:
                break
        else:
            print(i)
            break