import time
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def No():
    print(-1)
    exit()


N,M=input_int_list()
s_c_tuple_list=[input_int_list() for i in range(M)]
the_dict={}
for tup in s_c_tuple_list:
    s,c=tup
    if s==1 and c==0:
        No()
    if s in the_dict:
        if the_dict[s]==c:
            pass
        else:
            No()
    else:
        the_dict[s]=c

if 1 not in the_dict:
    if N==1:
        time.sleep(2)
        the_dict[1]=0
    else:
        the_dict[1]=1

the_num=int("".join([str(the_dict[i+1]) if i+1 in the_dict else str(0) for i in range(N)]))

print(the_num)
