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

for i in range(M):
    s, c = map(int, input().split())
    if v[s-1] < c:
        v[s-1] = c

v.reverse()
s = ''.join(map(str, v))
n = int(s)

if len(str(n)) == N:
    print(n)
else:
    print(-1)
