def main():
    ans = [-1, -1, -1]
    N,M = map(int, input().split())

    acc = True

    for i in range(M):
        s,c = map(int, input().split())
        if ans[s-1] != -1 and ans[s-1] != c:
            acc = False
            break
        ans[s-1] = c

    if acc == False:
        print(-1)
        return

    for i in range(0,1000):
        a1 = i//100
        a2 = (i%100)//10
        a3 = (i%10)

        if ans[0] != -1:
            if a1 != ans[0]:
                continue
        if ans[1] != -1:
            if a2 != ans[1]:
                continue
        if ans[2] != -1:
            if a3 != ans[2]:
                continue

        if len(str(i)) != N:
            continue

        print(i)
        return

    print(-1)

main()