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

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

if l[0] == 0:
    r = False

if r == True:
    print("".join(map(str, l)))
else:
    print(-1)