def run():
    n, m = tuple([int(e) for e in input().split()])
    pairs = []
    ss = []
    cc = []
    num = [0, 0, 0]

    for i in range(m):
        s, c = tuple([int(e) for e in input().split()])
        if tuple((s, c)) not in pairs:
            pairs.append(tuple((s, c)))
            ss.append(s)
            cc.append(c)

    for i in range(len(ss)):
        if(ss.count(i + 1) > 1):
            print(-1)
            return
        else:
            num[ss[i] - 1] = cc[i]

    if(n > 1):
        for i in range(n):
            if(num[i] == 0):
                if(i + 1 not in ss):
                    num[i] = 1
                else:
                    print(-1)
                    break
            else:
                break

    num = num[0: n]
    print(int("".join([str(e) for e in num])))


run()
