def main():
    N,M = map(int,input().split())
    tmp = [[] for _ in range(3)]
    for i in range(M):
        s,c = map(int,input().split())
        tmp[s-1].append(c)
    if len(tmp[0]) == 0:
        tmp[0].append(1)
    if len(tmp[1]) == 0:
        tmp[1].append(0)
    if len(tmp[2]) == 0:
        tmp[2].append(0)
    ans = [min(tmp[0]),min(tmp[1]),min(tmp[2])]
    tt = ""
    for i in range(3):
        for j in range(len(tmp[i])):
            if ans[i] != tmp[i][j]:
                tt = "-1"
    if len(ans) != N or tt == "-1" or ans[0] == 0:
        print("-1")
    else:
        print(*ans,sep="")

if __name__ == '__main__':
    main()