N,M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
num = [0,0,0]
if N < 1 or 3 < N or M < 0 or 5 < M:
    print("-1")
    exit()
for i in range(M):
    if sc[i][0] < 1 or N < sc[i][0] or sc[i][1] < 0 or 9 < sc[i][1]:
        print("-1")
        exit()
for i in range(M):
    if sc[i][0] == 1 and sc[i][1] == 0: # or sc[i][1] == 0 and sc[i][0] == 2 and  #値が０かつそれが１００の位 or 値が０かつそれが１０の位かつ１００がない
        print("-1")
        exit()
    else:
        for j in range(M-i-1):
            if sc[i][0] == sc[j+1][0]:
                if sc[i][1] != sc[j+1][1]:
                    print("-1")
                    exit()
                else:
                    #if sc[i][1] not in num:
                    num[sc[i][0]-1] = sc[i][1]
NUM = num[0] * 100 + num[1] * 10 + num[2]
print(NUM)
