
try :
    NandM = input().split(' ')
    N = int(NandM[0])
    M = int(NandM[1])
    silist = {}
    ans = 0
    
    for s in range(M):
        siandci = input().split(' ')
        si = int(siandci[0])
        ci = int(siandci[1])
        if si == 1:
            if ci == 0:
                raise ValueError
        if si in silist:
            if silist[si] == ci:
                pass
            else:
                raise ValueError
        else:
            silist[si] = ci
except ValueError:
    print(-1)
else:
    silist_key = sorted(silist)
    for k in silist_key:
        ans = ans + (10**(max(silist_key) - k))*silist[k]
    print(ans)