
n,m = map(int,input().split())
d = dict()
for i in range(m):
    k,v = map(int,input().split())
    if k in d:
        if d[k] !=v:
            print(-1)
            exit()
    else:
        d[k] = v
if 2 not in d:
    d[2] = 0
if 3 not in d:
    d[3] = 0
res = str(d[1])+str(d[2])+str(d[3])
if res == "000":
    print(-1)
    exit()
print(res)