import sys

n, m = tuple(map(int, input().split()))

conditions = list()

digit_cond = set()  # 桁数指定が被っているかのチェック
for i in range(m):
    condition = tuple(map(int, input().split()))  # (s, c)
    # 同じ条件が来た場合には何もしない
    if condition not in conditions:
        digit_cond.add(condition[0])
        conditions.append(condition)

# print(digit_cond)
# print(conditions)

if len(digit_cond) != len(conditions):
    print("-1")
    sys.exit()

conditions = list(conditions)

# conditions = sorted(conditions, key=lambda x: x[0])  # 指定する桁目でソート


def cond_digit(conditions, digit):
    for cond in conditions:
        if cond[0] == digit:
            return cond[1]
    return 0


ans = ""

for i in range(n):
    ans = ans + str(cond_digit(conditions, i + 1))

if len(ans) != len(str(int(ans))):
    print("-1")
    sys.exit()

print(ans)
