NM = list(map(int,input().split()))
N = NM[0]
M = NM[1]
SC = []
temp = [0] * N
temp2 = [True] * 9
temp3 = []
test = True
test2 = True
for i in range(M):
    SC.append(list(map(int,input().split())))
    Ldigit = SC[i][0]
    Lnum = SC[i][1]
    if temp2[Ldigit-1]:
        temp[Ldigit-1] = Lnum
        temp2[Ldigit-1] = False
    else:
        test2 = False
for i in SC:
    temp3.append("".join(map(str,i)))
if len(set(temp3)) != len(temp3):
    test2 = True
if "10" in temp3:
    test2 = False
if N > 0 and temp[0] == 0:
    temp[0] = 1
tempS = "".join(map(str,temp))
if test2:
    for i in range(999):
        if str(i) == tempS:
            print(i)
            test = False
if test or not test2:
    print(-1)