n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc = sorted(sc, reverse=True, key=lambda x:x[0])
if m == 0:
    print(-1)
    exit()
if sc[0][0] != n:
    print(-1)
    exit()
ans = [0] * n
ans[0] = 1
prev = sc[0]
for i in range(1, m):
    if prev[0] == sc[i][0] and prev[1] != sc[i][1]:
        print(-1)
        exit()
    ans[sc[i][0]-1] = sc[i][1]
    prev = sc[i]
print(''.join(map(lambda x: str(x), ans)))