def Main(N, M, S, C):
    digits = {1:set([]), 2:set([]), 3:set([])}
    for i in range(M):
        digits[S[i]].add(C[i])
    for k, v in digits.items():
        if len(v) >= 2:
            return -1
    if len(digits[1]) > 0 and list(digits[1])[0] == 0:
        return -1
    if len(digits[1]) == 0 and len(digits[2]) > 0 and list(digits[2])[0] == 0:
        return -1  
    ans_list = []
    for v in digits.values():
        if len(v) == 0:
            ans_list.append('0')
        else:
            ans_list.append(str(list(v)[0]))
    ans_str = "".join(ans_list)
    return eval(ans_str)
        
                

def main():
    N, M = map(int, input().split())
    S = [0]*M
    C = [0]*M
    for i in range(M):
        S[i], C[i] = map(int, input().split())
    print(Main(N, M, S, C))

if __name__ == '__main__':
    main()