# coding: utf-8

f = 1
n, m = map(int, input().split())

li = [-1] * n

for _ in range(m):
    s, c = map(int, input().split())
    if li[s-1] != -1 and li[s-1] != c:
        f = 0
        break
    else:
        li[s-1] = c

if li[0] == -1 or li[0] == 0:
    f = 0
else:
    while -1 in li:
        li[li.index(-1)] = 0

if f:
    for i in range(n):
        print(li[i], end='')
    print('')
else:
    print('-1')