def resolve():
    def main():
        N,M=map(int,input().split())
        S, C = [0] * M, [0] * M

        for i in range(M):
            S[i], C[i] = map(int, input().split())
            if i==0:
                dic={S[i]:C[i]}
            else:
                if S[i] not in dic.keys():
                    dic[S[i]]=C[i]
                elif dic[S[i]]!=C[i]:
                    return -1
        #dic=dict(sorted(dic.items(), key=lambda x: x[0]))
        ans=[0]*N
        for i,j in dic.items():
            ans[i-1]=j

        if len(ans)!=1 and ans[0]==0:
            return -1
        else:
            return ans

    val=main()
    if val==-1:
        print(-1)
    else:
        for i in val:
            print(i,end='')
        print()







resolve()