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

d = [0] * N
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if s == 0 and c == 0:
        print(-1)
        exit()
    if d[s] != 0 and d[s] != c:
        print(-1)
        exit()
    d[s] = c

if N >= 2:
    if d[0] == 0:
        d[0] = 1
              
str_d = []
for i in range(N):
    str_d.append(str(d[i]))

print(''.join(str_d))