N, M = map(int, input().split())
# print("N:", N, "M:", M)
s = [list(map(int, input().split())) for _ in range(M)]
# print(s)

c = []
f = []
for i in range(N):
    c.append(0)
    f.append(0)
# print(c)
# print(f)
flg = True
for i in s:
    if (f[i[0] - 1] == 0):
        c[i[0] - 1] = i[1]
        f[i[0] - 1] = i[1]
    elif f[i[0] - 1] > i[1]:
        c[i[0] - 1] = i[1]
        f[i[0] - 1] = i[1]

if flg == True:
    c = map(str, c)
    # print(c)
    d = ''.join(c)
    if d[:1] == "0":
        print("-1")
    else:
        print(d)
else:
    print("-1")