n, m = map(int, input().split())
if n == 1:
    _, c = map(int, input().split())
    print(c)
else:
    digits = [None for _ in range(n)]
    failflag = False
    for _ in range(m):
        s, c = map(int, input().split())
        s = s - 1
        if digits[s] is None or digits[s] == c:
            digits[s] = c
        else:
            failflag = True
            break
    if digits[0] == 0:
        failflag = True
    elif digits[0] is None:
        digits[0] = 1
    if failflag:
        print(-1)
    else:
        print(''.join(str(0) if digit is None else str(digit) for digit in digits))