# -*- coding: utf-8 -*-
# @Time    : 2020/3/1 19:59
# @Author  : DIRICHLET
# @File    : main.py

n,m=map(int,input().split())
mm={}
f=1
ans=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    if a not in mm:
        mm[a]=b
    else:
        if mm[a]!=b:
            print('-1')
            exit()
l=sorted(mm.keys())
for i in l:
    ans[i-1]=mm[i]
if ans[0]==0:
    print('-1')
    exit()
else:
    for i in ans:
        print(i,end='')