import sys

N, M = map(int, input().split())
sclist = {1:[], 2:[], 3:[]}
for i in range(M):
    s, c = map(int, input().split())
    sclist[s].append(c)

num = []

for i, sc in enumerate(sclist.values()):
    if len(sc) == 0:
        sclist[i+1].append(0)
    num.append(min(sc))

if N >= 2:
    if num[0] == 0:
        print('-1')
        sys.exit()


for i in num:
    print(i, end='')