N, M = map(int, input().split())
s, c = [], []
for i in range(M):
    _s, _c = map(int, input().split())
    s.append(_s)
    c.append(_c)

candidate = [-1] * N
for i, v in enumerate(s):
    if candidate[v-1] != -1 and candidate[v-1] != c[i]:
        print(-1)
        exit()
    candidate[v-1] = c[i]

if candidate[0] == 0:
    print(-1)
    exit()

a = [0 if i == -1 else i for i in candidate]
ans = int(''.join(map(str, a)))
if len(str(ans)) != N:
    print('1'+'0'*(N-len(str(ans))-1)+str(ans))
else:
    print(ans)
