n, m = map(int, input().split())

s = []
for i in range(m):
    s.append(list(map(int, input().split())))

if n == 1:
    for q in range(10):
        o = 0
        for l, z in s:
            if q == z:
                o += 1

        if o == len(s):
            print(q)
            exit()



else:
    for j in range(int("1" + "0"*(n-1)),int("1" + "0"*n)):
        g = 0
        for k, u in s:
            if int(str(j)[k-1]) == u:
                g += 1

            if g == len(s):
                print(j)
                exit()

print(-1)