n,m = map(int, input().split())
sc= [map(int, input().split()) for _ in range(m)]
s, c = [list(i) for i in zip(*sc)]

ans = 10001
for i in range(m):
    tmp = 0
    if s[i] == 0:
        tmp += 1
    elif tmp == m:
        print(0)

for l in range((10**(n-1)),10**n):
    ln = str(l)


    tmp = 0
    for j in range(m):
        if int(ln[int(s[j])-1]) == int(c[j]):
            tmp += 1
            # print(tmp)
            if tmp == m:
                ans = int(ln)
                print(ans)
                break

        else:
            # print(tmp)
            break
    if ans != 10001:
        break

if ans == 10001:
    print(-1)
