n = list(map(int,input().split()))
string_list=[list(map(int,input().split())) for i in range(n[1])]

tmp = 0
string_list.sort()

for i in range(len(string_list)-1):
    if(string_list[i][0] == string_list[i+1][0]):
        if(string_list[i][1] != string_list[i+1][1]):
            tmp = 1
    elif(string_list[i][0] > n[0]):
        tmp = 1

if(string_list[0][0] == 1 and string_list[0][1] == 0):
    tmp = 1

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

string_list2 = get_unique_list(string_list)

t = 0

if(tmp == 0):
    for i in range(n[0]):
        if(t < len(string_list2)):
            if(string_list2[t][0] == i+1):
                print(string_list2[t][1], end="")
                t += 1
            else:
                print(0, end="")
else:
    print(-1)