N, M = map(int, input().split())
SC = [[int(x) for x in input().split()] for _ in range(M)]

ans = [0] * N
flg = 0

for s, c in SC:
    if (flg>>(s-1))&1:
        ans[s-1] = min(ans[s-1], c)
    else:
        flg |= 1<<(s-1)
        ans[s-1] = c


ans = ''.join(map(str, ans))
ans = str(int(ans))

if len(ans)!=N:
    print(-1)
else:
    print(ans)