N,M = map(int,input().split())
lis = ["0"]*N
sl = []
cl = []
jud = True
ex = True
for i in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0:
        jud = False
    if c != 0:
        ex = False 
    sl.append(s)
    cl.append(c)
    if s in sl:
        if cl[sl.index(s)] != c:
            jud = False
    lis[s-1] = str(c)
if N == 1 and ex:
    jud = True
if jud:
    print(int("".join(lis)))
else:
    print("-1")