n, m = map(int, input().split())
s = [-1] * 3
for i in range(m):
    si, ci = map(int, input().split())
    if s[si-1] == -1:
        s[si-1] = ci
    s[si-1] = min(s[si-1], ci)

ans = ""
mcnt = 0
for i in range(n):
    if s[i] == -1:
        s[i] = 0
        mcnt += 1
    ans += str(s[i])

if mcnt == 3:
    print(-1)
elif ans != str(int(ans)):
    print(-1)
else:
    print(ans)
