from operator import itemgetter

n, m = map(int, input().split())
sc = sorted([list(map(int, input().split()))for _ in range(m)], key = itemgetter(0))
f = ''

if m == 0:
    print(0)
    exit()

if sc[0][0] != 1:
    f += '1'
else:
    f += str(sc[0][1])

last = 1
for i in  range(1, m):
    if sc[i-1][0] == sc[i][0]:
        if sc[i][1] != sc[i][1]:
            print(-1)
            exit()
        else:
            continue
    elif sc[i][0] != last + 1:
        f += '0'
        last = sc[i][0]
    f += str(sc[i][1])
    last = sc[i][0]

if len(f) == n:
    print(f)
else:
    print(-1)