N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)
s_true = [j for j, k in enumerate(s) if k <= N]
s = [s[l] for l in s_true]
c = [c[m] for m in s_true]
ans_list = [0] * N
ans = ""
if M == 0:
    print(-1)
    exit()
else:
    for n in range(len(s)):
        ans_list[s[n] - 1] = c[n]
if ans_list[0] == 0 and N != 1:
    print(-1)
else:
    for a in ans_list:
        ans += str(a)
    print(int(ans))