import sys
input_line = [int(i) for i in input().split(" ")]
n = input_line[0]
m = input_line[1]

ans = ["1"] + ["0"] * (n - 1)
flag = 0
for i in range(m):
    input_line = input().split(" ")
    if int(input_line[0]) == 1 and flag == 0:
        ans[int(input_line[0]) - 1] = input_line[1]
        flag = 1
        continue
    elif int(input_line[0]) == 1 and flag == 1:
        print(-1)
        sys.exit()
    if ans[int(input_line[0]) - 1] == "0" or ans[int(input_line[0]) - 1] == input_line[1]:
        ans[int(input_line[0]) - 1] = input_line[1]
    else:
        print(-1)
        sys.exit()

if m == 0 and n == 1:
    ans[0] = "0"

ans_num = int("".join(ans))
if n == len(str(ans_num)):
    print(ans_num)
else:
    print(-1)
