
digit, m = map(int, input().split())

rules = []
for _ in range(m):
    rules.append(list(map(int, input().split())))

numlst = [ -1 for _ in range(digit) ]

for rule in rules:
    numindex = rule[0] - 1
    # ルールの重複
    if numlst[numindex] != -1 and numlst[numindex] != rule[1]:
        print(-1)
        exit()
    numlst[numindex] = rule[1]

# 先頭が０の場合
if digit > 1 and numlst[0] == 0:
    print(-1)
    exit()


# 先頭がマイナス１の場合、０ではなく１にする
if numlst[0] == -1:
    numlst[0] = 1

# 文字列の組み立ておよび出力
for n in numlst:
    if n == -1:
        n = 0
    print(n, end="")
print()