n, m = map(int, input().split())
ans = [0] * n
ans[0] = 1
data = [0] * m
for i in range(m):
    data[i] = list(map(int, input().split()))
arr = [0] * 3  # 変更回数の記録
for j in range(m):
    s = data[j][0]-1
    c = data[j][1]
    before = ans[s]
    ans[s] = c
    after = ans[s]
    if before != after or after == 0:
        arr[s] += 1
print(arr)
print(ans)
for k in range(3):
    if arr[k] > 1:  # 変更回数が2回以上でだめ
        print(-1)
        exit()
if ans[0] == 0 and n != 1:  # 答えの先頭が0はだめ
    print(-1)
    exit()
print(*ans, sep='')