N, M = map(int, input().split())
number_list = [0] * N
cond_list = []
for i in range(M):
    s, c = map(int, input().split())
    cond_list.append([s, c])

def check():
    for s, c in cond_list:
        i = s-1
        if number_list[i] > 0 and number_list[i] != c:
            return "-1"
        if N > 1 and s == 1 and c == 0:
            return "-1"
        number_list[i] = c

    if number_list[0] == 0:
        number_list[0] = 1

    answer = ""
    for i in range(N):
        answer += "{0}".format(number_list[i])

    return answer
print(check())
