s_text = list(map(int, input().split()))
output = [0] * s_text[0]
flag = True
for i in range(s_text[1]):
    text = list(map(int, input().split()))

    if text[0] == 0 and text[1] == 0:
        flag = False
    if output[text[0] - 1] == 0 or output[text[0] - 1] == text[1]:
        output[text[0] - 1] = text[1]
    else:
        flag = False

if output == [0] * s_text[0] and s_text[0] != 1:
    output[0] = 1

if flag:
    print("".join(map(str, output)))
else:
    print("-1")