def main():
    N,M = map(int,input().split())
    tmp = [[] for _ in range(N)]
    ans = ""
    for i in range(M):
        s,c = map(int,input().split())
        tmp[s-1].append(c)
    for i in range(N):
        if len(set(tmp[i])) == 1 or len(set(tmp[i])) == 0:
            continue
        else:
            ans = "-1"
            break
    if ans == "-1":
        print(ans)
    else:
        if len(tmp[0]) != 0 and (tmp[0][0] == 0 and N != 1):
            print("-1")
        else:
            ans = [0]*N
            if len(tmp[0]) == 0:
                ans[0] = 1
            else:
                ans[0] = tmp[0][0]
            for i in range(1,N):
                if len(tmp[i]) == 0:
                    ans[i] = 0
                else:
                    ans[i] = tmp[i][0]
            print(*ans,sep="")

if __name__ == '__main__':
    main()