n, m = map(int, input().split())
scs = []
for i in range(m):
    scs.append(list(map(int, input().split())))
    
def set_number(scs):
    number = [-1] * n
    for sc in scs:
        if number[sc[0] - 1] == -1:
            number[sc[0] - 1] = sc[1]
        elif number[sc[0] - 1] != sc[1]:
            return None
    return number
  
def guess_number(number):
    if number is None:
        return -1

    if number[0] == 0:
        return -1
    
    guess = 0
    for i in range(n):
        if i == 0 and  number[i] == 0:
            guess += (10 ** (n - i - 1))
        elif number[i] == -1:
            pass
        else:
            guess += number[i] * (10 ** (n - i - 1))

    return guess
  
number = set_number(scs)
print(guess_number(number))