N, M = map(int, input().split())
conditions = [tuple(map(int, input().split())) for _ in range(M)]
num = [0] * N
checked = [None] * N
for s, c in conditions:
    s -= 1
    if checked[s] is None:
        checked[s] = c
        num[s] = c
    else:
        if checked[s] == c: continue
        else:
            print(-1)
            break
else:
    if checked[0] is None and num[0] == 0: num[0] = 1
    print(''.join(str(n) for n in num) if num[0] != 0 else -1)