#157
def main():
    N, M = map(int,input().split())
    num = [-1]*N
    for i in range(M):
        s, c = map(int,input().split())
        if(s==1 and c==0 and N!=1):
            print(-1)
            return
        if(num[s-1]==-1 or num[s-1]==c):
            num[s-1] = c
        else:
            print(-1)
            return
    result = ''
    for i in ramge(N):
        if(num[i]!=-1):
            result+=str(num[i])
        else:
            if(N==1):
                result+='0'
            elif(i==0):
                result+='1'
            else:
                result+='0'
    print(result)

main()