


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

s_list = []
c_list = []

flag = True
for i in range(M):
    s,c= map(int,input().split())

    if s > N:
        flag = False
        break
    try:
        double = s_list.index(s)
        if double >= 0:
            if c != c_list[double]:
                flag = False
                break
        else:
            continue
    except ValueError:
        s_list.append(s)
        c_list.append(c)
   

#print(s_list)
#print(c_list)

sum = 0

for j in range(1,N+1):
    #if len(s_list) <= j:
    #    continue
    

    tt = N - j
    keta = 10**tt
    if keta == 0:
        keta = 1
    

    try:
        h = s_list.index(j)
        if j == 1:
            if c_list[h] == 0:
                flag = False
                break
        sum += c_list[h] * keta
    except ValueError:
        if j != N:
            sum += 0 * keta
        else:
            sum += 1 * keta

        

if flag:
    print(sum)
else:
    print(-1)