# -*- coding: utf-8 -*-

n, m = map(int, input().split())

s = ["" for i in range(m)]
c = ["" for i in range(m)]

for i in range(m):
    s[i], c[i] = map(int, input().split())
#print(s,c)

#----------------
#sに同じ数値があるとき、それらに対応するcが異なっていたら×

dict = {}
for i in range(m):
    #既にキーがあれば
    if s[i] in dict:
        #同じものか確認
        isSame = dict[s[i]] == c[i]
        if isSame:
            pass
        else:
            print(-1)
            exit()
    else:
        dict[s[i]] = c[i]



#n>=2のとき、s=1に対応するcが0であったら×
if n >= 2:
    try:
        idx = s.index(1)
    except: #s=1がそもそもなければスルー
        pass

    if c[idx] == 0:
        print(-1)
        exit()

#----------------
ans = []
for i in range(1, max(s)+1):
    if i in s:
        idx = s.index(i)
        #print("idx: " + str(idx))
        ans.append(c[idx])
    else:
        ans.append(0)

start_idx = 0
test = 0
for i in range(len(ans)):
    if ans[i] == 0:
        test += 1
        pass
    else:
        start_idx = i
        break

ans = ans[start_idx:]
finalans = []
for i in range(len(ans)):
    finalans.append(str(ans[i]))

if test >= 1:
    pref = "1" * test
    print(pref + "".join(finalans))
else:
    print("".join(finalans))

