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)

ans = "-1"
for i in range(10**(n - 1), 1000):
    i = str(i)

    # print(i)

    flag = False
    for cond in conditions:
        # print(cond)
        if i[cond[0] - 1] == str(cond[1]):
            flag = True
            ans = i
        else:
            flag = False
            break

    if flag:
        print(ans)
        break

# 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)
