def main():
    N , M = map(int, input().split())
    frag_error = 0
    si_old, ci_old = 0, 0
    s1 = None
    s2 = None
    s3 = None
    s4 = None
    s5 = None
    s6 = None
    c1 = None
    c2 = None
    c3 = None
    c4 = None
    c5 = None
    c6 = None
    for i in range(1,M+1) :
        si, ci = map(int, input().split())
        if si == si_old and ci != ci_old :
            frag_error = 1
        if si == 1 :
            s1, c1 = si, ci
        elif si == 2 :
            s2, c2 = si, ci
        elif si == 3 :
            s3, c3 = si, ci
        elif si == 4 :
            s4, c4 = si, ci
        elif si == 5 :
            s5, c5 = si, ci
        elif si == 6 :
            s6, c6 = si, ci
        else :
            pass
        si_old, ci_old = si, ci

    if M > N or frag_error == 1:
        print ("-1")
    elif N == 1 and c1 == 0 :
        print ("0")
    elif N >= 2 and c1 == 0 :
        print ("-1")
    elif N >= M and N == 1 and c1 != 0 :
        print (str(c1))
    elif N >= M and N == 2 and c1 != 0 :
        if c2 != None :
            print (str(c1) + str(c2))
        else :
            print (str(c1) + "0")
    elif N >= M and N == 3 and c1 != 0 :
        if c2 != None and c3 != None :
            print (str(c1) + str(c2) + str(c3))
        elif c2 != None and c3 == None :
            print(str(c1) + str(c2) + "0")
        elif c2 == None and c3 != None :
            print(str(c1) + "0" + str(c3))
        elif c2 == None and c3 == None :
            print(str(c1) + "00")


if __name__ == '__main__':
    main()