def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    ans = [0]*N
    ans[0] = 1
    flag = [False]*N
    for i in range(M):
        if sc[i][0] == 1 and sc[i][1] == 0:
            ans = "-1"
            break
        if flag[sc[i][0] - 1] and ans[sc[i][0] - 1] != sc[i][1]:
            ans = "-1"
            break
        else:
            ans[sc[i][0] - 1] = sc[i][1]
            flag[sc[i][0] - 1] = True
    if ans == "-1":
        print(ans)
    else:
        ans = list(map(str,ans))
        print(*ans,sep="")


if __name__ == '__main__':
    main()