N, M = input().split(" ")
N = int(N)
M = int(M)

s = []
c = []

one_list = []
two_list = []
three_list = []

for i in range(M):
    tmp_s, tmp_c = input().split(" ")
    tmp_s = int(tmp_s)
    tmp_c = int(tmp_c)
    s.append(tmp_s)
    c.append(tmp_c)
    if tmp_s == 1:
        one_list.append(tmp_c)
    elif tmp_s == 2:
        two_list.append(tmp_c)
    elif tmp_s == 3:
        three_list.append(tmp_c)
    else:
        print("Error")

if len(set(one_list)) > 1:
    print(-1)
    exit()

if len(set(two_list)) > 1:
    print(-1)
    exit()

if len(set(three_list)) > 1:
    print(-1)
    exit()


result = ""
for i in range(N):
    result += "0"


str_list = list(result)
for i in range(M):
    str_list[s[i] - 1] = str(c[i])

if str_list[0] == "0":
    print(-1)
    exit()

print("".join(str_list))
