n, m = map(int, input().split())
x = [0] * n

exist = True

for i in range(m):
    s, c = map(int, input().split())
    if s == 1:
        if c == 0:
            exist = False
        else:
            if x[0] != 0:
                if x[0] != c:
                    exist = False
            else:
                x[0] = c
    else:
        if x[s-1] != 0 and x[s-1] != c:
            exist = False
        else:
            x[s-1] = c

if n >= 2 and x[0] == 0:
    exist = False
            
if exist:
    print("".join(map(str,x)))
else:
    print(-1)
