s = input().split()
n = int(s[0])
m = int(s[1])


init = list(input().split() for _ in range(m))
m_box = list(False for _ in range(m))
n_box = list(False for _ in range(n))

flag = 0




for i in range(m):
    if(n_box[int(init[i][0])-1] == False or n_box[int(init[i][0])-1] == init[i][1]):
        n_box[int(init[i][0])-1] = init[i][1]
    else:
        flag = 1
        break
        
n_box = [int(i) for i in n_box]

moji =""

#print(n_box)
#print(flag)

if(n_box[0] != 0 and flag == 0):
    for i in n_box:
        moji += str(i)
    print(moji)
else:
    flag = 1


if(flag == 1):
    print(-1)