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)
ans_list = [0] * N
ans = ""
if M == 0:
    print(-1)
    exit()
else:
    for j in range(M):
        ans_list[s[j] - 1] = c[j]
if ans_list[0] == 0:
    print(-1)
else:
    for a in ans_list:
        ans += str(a)
    print(int(ans))