N,M = map(int,input().split())
s = []
c = []
if N == 1:
    minn = "0"
elif N == 2:
    minn = "00"
elif N == 3:
    minn = "000"
count = 0
minnlist = list(minn)
for i in range(M):
    am, pm = map(int,input().split())
    s.append(am)
    c.append(pm)

for i in range(M):
    if minnlist[s[i]-1] != "0" and minnlist[s[i]-1] != str(c[i]):
        count = -1
        break
    else:
        minnlist[s[i]-1] = str(c[i])

#print(minnlist)
if minnlist[0] == "0":
    count = -1

hiku = ''.join(map(str,minnlist))
#print(int(hiku))

if count == -1:
    print(-1)
else:
    print(hiku)