def main():
    N,M = map(int,input().split())
    ansl = [-1]*N
    isok = True

    for i in range(M):
        s,c = map(int, input().split())
        if ansl[s-1]<0 : ansl[s-1]=c
        elif ansl[s-1]!=c : isok = False

    if ansl[0] ==  0: isok = False
    if ansl[0] == -1: ansl[0] = 1
    for i in range(1,N):
        if ansl[i] == -1 : ansl[i] = 0

    if isok:
        ans = ''
        for n in ansl: ans+=str(n)
    else:
        ans = -1
    print(ans)


    """
    sc = []
    for i in range(M):
        new_sici = list(map(int, input().split()))
        equal_flag = False
        for sici in sc:
            if sici[0] == new_sici[0] and sici[1]!=new_sici[1]:
                print(-1)
                return
            if sici == new_sici: equal_flag = True
        if not equal_flag : sc.append(new_sici)

    sc.sort()
    ansl = [0]*N
    if sc[0][0] > 1 : ansl[0]=1
    for sici in sc: ansl[sici[0]-1]=sici[1]

    ans = ''
    for n in ansl: ans+=str(n)
    print(ans)
    """

    return

if __name__ == "__main__":
    main()