n, m = map(int, input().split())
c = {}
for _ in range(m):
    d, f = map(int, input().split())
    if d in c and c[d] != f:
        print(-1)
        break
    else:
        c[d] = f
        
    if 1 in c and n != 1:
        if c[1]==0:
            print(-1)
            break
else:
    if 1 in c:
        o = str(c[1])
    else:
        o='1'

    for i in range(1, n):
        if i+1 in c:
            o += str(c[i+1])
        else:
            o += '0'
    print(o)