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

p = [[],[],[]]
for i in range(m):
    if l[i][0]== 1:
        p[0].append(l[i][1])
    elif l[i][0]== 2:
        p[1].append(l[i][1])
    else:
        p[2].append(l[i][1])

#print(p)

if len(p[0]) == 0:
        p[0].insert(0,1)
#print(p)

for j in range(len(p)):
    if len(p[j]) == 0:
        p[j].append(0)

#print(p)

if len(set(p[0])) > 1 or len(set(p[1])) > 1 or len(set(p[2])) > 1:
    print('-1')
    exit()

q = []
for k in range(len(p)):
    q.append(str(p[k][0]))
#print(q)


if q[0] == '0':
    print('-1')
    exit()

if q[0] == '0' and q[1] == '0':
    print('-1')
    exit()

if q[0] == '0' and q[1] == '0' and q[2] == '0':
    print('-1')
    exit()

print(''.join(q))

