N, M = map(int, input().split())

d = {}
a = True
for i in range(M):
    s, c = map(int, input().split())
    if s in d:
        if d[s] != c:
            a = False
    d[s] = c

if 1 in d:
    if d[1] == 0 and N != 1:
        a = False
else:
    d[1] = 1

ans = 0
for i in range(1, N+1):
    if i in d:
        ans += pow(10,N-i)*d[i]

if a:
    print(ans)
else:
    print(-1)
