import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
sc = [list(map(int, readline().split())) for _ in range(m)]

l = ['x']*3
for s, c in sc:
    if l[s - 1] == 'x':
        l[s - 1] = str(c)
    elif l[s - 1] != str(c):
        print('-1')
        exit()
l = "".join(l)
l = int(l.replace('x', '0'))
ans = l if len(str(l)) == n else '-1'
print(ans)