n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
temp = [-1 for i in range(n)]
flag = True
if [1,0] in s:
    flag = False
else:
    for i in s:
        if not temp[i[0]-1] in [-1,i[1]]:
            flag = False
            break
        temp[i[0]-1] = i[1]
ans = ""
if not flag:
    ans = "-1"
else:
    if temp[0]==-1:
        temp[0] = 1
    if n>1:
        for i in range(1,n):
            if temp[i]==-1:
                temp[i] = 0
        for i in temp:
            ans += str(i)
print(ans)