N, M = [int(i) for i in input().split()]
di = {}
flag = True
for _ in range(M):
    s, c = [int(i) for i in input().split()]
    if(s in di):
        if(di[s] != c):
            print(-1)
            flag = False
            break
    else:
        di[s] = c

if(1 in di):
    if(di[1]==0):
        if(N==1):
            print(0)
        else:
            print(-1)
        flag = False

if(flag):
    for i in range(10**(N-1), 10**N):
        x = str(i)
        ok = True
        for ind, s in enumerate(x):
            if(ind+1 in di):
                if(di[ind+1] != int(s)):
                    ok = False
                    continue
        if(ok):
            print(i)
            break
    else:
        print(-1)


