

def solve(N,M,S,C) -> int:
    if(N == 1): return min(C)
    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):
        if(0 in dic[1]):
            dic[1].remove(0)
        for i in range(2,N+1):
            if(dic[i] == []):
                dic[i].append(0)
    if(dic[1]==[]):
        return -1
    else:
        ans = ""
        for values in dic.values():
            tmp = min(values)
            ans+= str(tmp)
        return int(ans)
    


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()
