n = list(map(int, input().split()))

def getNum(n, m):
    num = [-1] * n
    for i in range(m):
        digits = list(map(int, input().split()))
        if (digits[0] == 1 and digits[1] == 0 and n != 1) or (num[digits[0] - 1] != -1 and num[digits[0] - 1] != digits[1]):
            return -1
        else:
            num[digits[0] - 1] = digits[1]
    number = ""
    for item in num:
        if item == -1:
            item = 0
        number += str(item)
    return number

print(getNum(n[0], n[1]))