N, M = map(int, input().split())

inList = list([])

for indx in range(M):
    inList.append(list(map(int, input().split())))

flag = 0

for indx in range(M):
    if (((N > 1) and (inList[indx][0] == 1) and (inList[indx][1] == 0)) or
        ((inList[indx][0] > N))):
        flag = -1
    
    for inside_indx in range(indx, M):
        if ((inList[indx][0] == inList[inside_indx][0]) and (inList[indx][1] != inList[inside_indx][1])):
            flag = -1

if flag == -1:
    print(-1)
elif ((flag != -1) and (N == 1)):
    print("0")
else:
    mystr = "1" + ("0" * (N-1))
    mystr = list(mystr)

    for indx in range(M):
        mystr[(inList[indx][0] - 1)] = str(inList[indx][1])
    
    print("".join(mystr))