

def solve(N,M,S,C) -> int:
    dic = {key:[] for key in range(1,N+1)}
    ans = 10**5
    for s,c in zip(S,C):
        if(s in dic.keys()):
            dic[s].append(c)
        else:
            dic[s]=[c]
    if(N != 1):
        for i in range(2,N+1):
            if(dic[i] == []):
                dic[i].append(0)
    # print(dic)
    for n in range(10**N):
        length = len(str(n))
        if(length == N):
            for i in range(1,N+1):
                if((int(str(n)[i-1]) in dic[i])==False):
                    # print(str(n)[i - 1],dic[i])
                    break
            else:
                ans = min(ans,n)

    return ans if(ans != 10**5) else -1


def main():
    N,M = map(int,input().split())
    S = []
    C = []
    for _ in range(M):
        s,c = map(int,input().split())
        S.append(s)
        C.append(c)
    # solve()
    print(solve(N,M,S,C))
if __name__ == "__main__":
    main()
