# coding: utf-8
# Your code here!

line = input().split(" ")
n = int(line[0])
m = int(line[1])

result = ["0"] * n
out = 0

for i in range(m):
    line = input().split(" ")
    # print(line)
    line_n = int(line[0])
    # line_m = int(line[1])
    if result[line_n - 1] == "0":
        result[line_n - 1] = line[1]
    elif result[line_n - 1] != line[1]:
        out = -1
    
if result[0] == "0":
    out = -1
# print(result)
if out == 0:
    print("".join(map(str,result)))
else:
    print(out)
