N, M = map(int, input().split())
SC = []

for _ in range(M):
    SC.append(tuple(map(int, input().split())))

SC = set(SC)

mem = []
ans = ['0'] * N
for idx, sc in enumerate(SC):
    if (sc[0] in mem)or (sc[0] == 1 and sc[1] == 0):
        print(-1)
        exit()
    mem.append(sc[0])
    ans[sc[0] - 1] = str(sc[1])

if ans[0] == '0':
    print(-1)
else:
    print(int(''.join(ans)))