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

start = 0 if n == 1 else 10**(n-1)
for j in range(start,10**n+1):
    judge = 0
    for k in range(m):
        if str(j)[s[k]-1] == str(c[k]):
            judge += 1
        else:
            pass

    if judge == m:
        print(j)
        break
    elif j == 10**n:
        print(-1)
        #print(judge) #test
    else:
        pass